Django Model Sync Table

database, django, django-models, python, synchronization

Solution

Alas, Django does not support any easy solution to this.

The only thing django will do for you, is restart your database with new tables that match your new models:

$ #DON'T DO THIS UNLESS YOU CAN AFFORD TO LOSE ALL YOUR DATA!
$ python PROJECT_DIR/manage.py syncdb

the next option is to use the various sql* options to manage.py to see what django would do to match the current models to the database, then issue your own `ALTER TABLE` commands to make everything work right. Of course this is error prone and difficult.

The real solution is to use a database migration tool, such as south to generate migration code.

Here is a similar question with discussion about various database migration options for django.

Problem

If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?

Original source

Related problems