Thursday, September 8, 2011

Django database schema validation after migration

It has happened to me (perhaps as a result of not being careful enough) that after applying some migrations the database is left in a state that is different from that which would have if it had being created anew (with syncdb, for example).

I think the problem was some FK or something.

So I was looking for ways to ensure that the database was perfectly in sync with the Django models. Of course South is extremely useful, among other things because of data migrations.

What I have in mind is something like this: first, use South as usual. At the end, if you want to be 100% sure, export the data (with manage.py dumpdata), then disable South, recreate the database with syncdb, and reload the data (manage.py loaddata).

No comments:

Post a Comment