views:

698

answers:

6

I'm currently looking at the Python framework Django for future db-based web apps as well as for a port of some apps currently written in PHP. One of the nastier issues during my last years was keeping track of database schema changes and deploying these changes to productive systems. I haven't dared asking for being able to undo them too, but of course for testing and debugging that would be a great feature. From other questions here (such as this one or this one), I can see that I'm not alone and that this is not a trivial problem. Also, I found many inspirations in the answers there.

Now, as Django seems to be very powerful, does it have any tools to help with the above? Maybe it's even in their docs and I missed it?

+1  A: 

Last time I checked (version 0.97), syncdb will be able to add tables to sync your DB schema with your models.py file, but it cannot either:

  • rename or add a column on a populated db... You need to do that by hand.
  • refactorize your model (like split a table into two), and repopulate your db accordingly.

It might be possible though to write a django script to make the migration by playing with the two different managers... but that might take ages if your DB is big...

poulejapon
+9  A: 

There are at least two third party utilities to handle DB schema migrations, South and Django Evolution. I haven't tried either one, but I have heard some good things about South, though Evolution has been around a little longer.

Also, look at SchemaEvolution on the Django wiki. It is just a wiki page about migrating the db.

varikin
South seems to be the best date, after playing around with Django Evolution, i think South's Data Migration is the killer feature. I don't think Django Evolution has Data Migration as yet. only Schema Evelution
Rasiel
A: 

And now there's also dmigrations. From announcement:

django-evolution attempts to address this problem the clever way, by detecting changes to models that are not yet reflected in the database schema and figuring out what needs to be done to bring the two back in sync. In contrast, dmigrations takes the stupid approach: it requires you to explicitly state the changes in a sequence of migrations, which will be applied in turn to bring a database up to the most recent state that reflects the underlying models.

This means extra work for developers who create migrations, but it also makes the whole process completely transparent—for our projects, we decided to go with the simplest system that could possibly work.

(My bold)

jamting
A: 

I heard lot of good about Django Schema Evolution Branch and those were opions of actual users. It mostely works out of the box and do what it should do.

Łukasz
A: 

U should lookup Dmigrations, it functions a little bit diffrent from django-eveoltions. It shows you everything it is doing and for compliccated things it asks you for your intervetnions. It should be great.

Slavus
+1  A: 

There was a panel session on DB schema changes at the recent DjangoCon; there is a video of the session (thanks to Google), which should provide some useful information on a number of these utilities.

TimB
Nice session. I guess I made up my mind in sticking with django evolution.
Farinha