From 0a8a6b4683a4d40181e39e000fd3c05ab4b3f652 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 15 May 2018 12:19:30 -0400 Subject: [PATCH] Add clarifying section about historical migration models --- docs/topics/migrations.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/topics/migrations.txt b/docs/topics/migrations.txt index a45966ccb0..e3f7513433 100644 --- a/docs/topics/migrations.txt +++ b/docs/topics/migrations.txt @@ -352,8 +352,19 @@ Historical models When you run migrations, Django is working from historical versions of your models stored in the migration files. If you write Python code using the :class:`~django.db.migrations.operations.RunPython` operation, or if you have -``allow_migrate`` methods on your database routers, you will be exposed to -these versions of your models. +``allow_migrate`` methods on your database routers, you **need to use** these +historical model versions rather than importing them directly. + +.. warning:: + + If you import models directly rather than using the historical models, + your migrations *may work initially* but will fail in the future when you + try to re-run old migrations (commonly, when you set up a new installation + and run through all the migrations to set up the database). + + This means that historical model problems may not be immediately obvious. + If you run into this kind of failure, it's OK to edit the migration to use + the historical models rather than direct imports and commit those changes. Because it's impossible to serialize arbitrary Python code, these historical models will not have any custom methods that you have defined. They will,