Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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:

  • 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 large.

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.

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)

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top