I conserve a Django project having a database which has several model constraints which have fallen from sync using the actual database. So, for instance, some model fields have null=False set, however the database permits NULLs for that corresponding database column.
I am curious if there's a software application, in both Django or perhaps a third-party Python script, which will compare the SHOW CREATE TABLE output (within this situation, using MySQL syntax) for every table and compare it using the python manage.py sql output, to focus on the discrepancies.
Granted, in a perfect situation, the database wouldn't drop out of sync using the Django model code to begin with, consider this is where I'm, I am curious if there is a fix for your problem before I write one myself or perform the comparison by hand.
./manage.py inspectdb creates the model file akin to the models which exist inside the database.
You are able to diff it together with your current model files utilizing a standard unix diff or other fancy diffing tool to obtain the difference and plan your migration strategy.
As the former appears simpler and, you may also begin to see the diff in the sql level.
./manage.py sqlall creates the sql for that current db schema and correspondingly
show create table table-name shows the sql for that table creation.
You might like to refer http://code.google.com/p/django-evolution/ which once auto migrated the condition from the db towards the one in the present models. - Note however, this project now has wrinkles and appears abandoned.
Used to do develop a fast and dirty way of doing things i referred to. It isn't perfect, but when you take
./manage.py testserver, the exam database is going to be produced in line with the model code. Then (using MySQL-specific syntax), you are able to dump the schema for that regular database and also the test database to files:
$ mysqldump -uroot -p [database_name] --no-data=true > schema.txt $ mysqldump -uroot -p [test_database_name] --no-data=true > test_schema.txt
You'll be able to simply diff schema.txt and test_schema.txt and discover the variations.
For PostgreSQL, perform a
manage.py syncdb on the temporary empty database, then dump production and temporary databases with
pg_dump -sOx and compare the resulting files. Among visual diff tools, a minimum of GNOME Meld appears to deal well with PostgreSQL dumps.