Search code examples
djangodjango-modelsdjango-databasedjango-syncdb

Is there a way to update the database with the changes in my models?


Possible Duplicate:
update django database to reflect changes in existing models

I've used Django in the past and one of the frustrations I've had with it as an ORM tools is the inability to update an existing database with changes in the model. (Hibernate does this very well and makes things really easy for updating and heavily modifying a model and applying this to an existing database.) Is there a way to do this without wiping the database every time? It gets really old having to regenerate admin users and sites after every change in the model which I'd like to play with.


Solution

  • You will want to look into South. It provides a migrations system to migrate both schema changes as well as data from one version to the next.

    It's quite powerful and the vast majority of changes can be handled simple by going

    manage.py schemamigration --auto
    manage.py migrate
    

    The auto functionality does have it limits, and especially if the change is going to be run on a production system eventually you should check the code --auto generated to be sure it's doing what you expect.

    South has a great guide to getting started and is well documented. You can find it at http://south.aeracode.org