do migrations (Django 1.7+) handle production data?

37 views
Skip to first unread message

Abraham Varricatt

unread,
Jan 14, 2015, 2:03:24 AM1/14/15
to django...@googlegroups.com
Hello everyone,

One of the biggest features introduced in Django 1.7 are migrations. They can broadly be classified into 2 types - 
* schema migrations
* data migrations

Schema migrations deal with changes to the database schema. eg - changing max_digits of a DecimalField.
Data migrations revolve around the actual data in your database and are not automatically taken care of.

My question is; 

Why is there so much praise for the Django (1.7) migrations feature if it can't handle data? Yes, I can understand the convenience of schema migrations, but without it being accompanied by data migrations, what's the point? (I'm assuming that this is something run on a production environment. For test/development environments, the data can arguably be worthless)

Puzzled,
Abraham V.

Russell Keith-Magee

unread,
Jan 14, 2015, 2:26:45 AM1/14/15
to Django Users
What gave you the impression that Django's migrations doesn't handle data? There's a section in the Migration topic guide in Django's documentation entitled "Data Migrations":


Yours,
Russ Magee %-)

Abraham Varricatt

unread,
Jan 14, 2015, 7:34:42 AM1/14/15
to django...@googlegroups.com
To be more specific, the document you link clearly mentions that "Django can’t automatically generate data migrations for you"

And this is what puzzles me. If it isn't automated and is something that needs to be done manually, what's so great about it's inclusion in Django 1.7?

Slowly discovering django,
Abraham V.

James Bennett

unread,
Jan 14, 2015, 7:43:28 AM1/14/15
to django...@googlegroups.com
On Wed, Jan 14, 2015 at 6:34 AM, Abraham Varricatt <abraham....@googlemail.com> wrote:

To be more specific, the document you link clearly mentions that "Django can’t automatically generate data migrations for you"


And this is what puzzles me. If it isn't automated and is something that needs to be done manually, what's so great about it's inclusion in Django 1.7?

Django cannot read your mind to figure out what specific changes to your data you'd like to have happen. So writing the logic of the data migration is up to you.

Django *can* usually deduce the necessary schema changes from examining what the models looked like before and after. And that's the difference.

Markus Holtermann

unread,
Jan 14, 2015, 8:31:12 AM1/14/15
to django...@googlegroups.com
Hey Abraham,

to be more specific, when you used South and ran "manage.py
datamigration" [1] you got an empty migration file with a forwards and
backwards method where you had to fill out the blanks and tell South
what to do, e.g. to create a certain object in the database.

With Django's migration system you get the same with running "manage.py
makemigrations --empty". Django will generate an empty migration file
that you can fill with the operations to run.

Django offers "migrations.RunPython" to run arbitrary Python code, and
"migrations.RunSQL" do perform raw SQL queries. (For documentation
please see the links Russell send earlier).

Best

/Markus

[1] http://south.readthedocs.org/en/latest/commands.html#datamigration
Reply all
Reply to author
Forward
0 new messages