Basically change a area inside a Django model, how do i synchronize it using the database tables? Should i get it done by hand around the database or it is possible to tool that does aids in the procedure?
Alas, Django doesn't support any easy means to fix this.
The only real factor django is going to do for you personally, is restart your database with new tables that suit your new models:
$ #DON'T DO THIS UNLESS YOU CAN AFFORD TO LOSE ALL YOUR DATA! $ python PROJECT_DIR/manage.py syncdb
the following option is by using the different sql* choices to manage.py to determine what django would do in order to match the present models towards the database, then problem your personal
ALTER TABLE instructions to create everything work right. Obviously this really is error prone and hard.
The actual solution is by using a database migration tool, for example south to create migration code.
This is a similar question with discussion about various database migration choices for django.
Django Evolution might help, but the best choice is really to organize your schema ahead of time, in order to make simple modifications by hand. Or, to become prepared to toast your test data by shedding tables and re-syncing.
Can't appear to have the ability to give a comment towards the marked answer, most likely because I've not got enough repetition (be nice if that's the case explained so though).
Anyway, just added that within the clarified publish, I believe that it is wrong about syncdb - syncdb does not touch tables once they've been produced and also have data inside them. You need to not lose data by calling it (otherwise, how may you add new tables for brand new applications?)
In my opinion the poster was mentioning towards the totally reset command rather, which does lead to loss of data - it'll drop the table and recreate it and therefore it has all of the latest model changes.
Django doesn't offer this as they are.
Here's some good info in the Django Book on doing it by hand (see Making Changes to some Database Schema). This works best for straightforward, simple changes.
Longer-term, you'll most likely desire to use a migration tool. You will find three major options:
- Dmigrations (compiled by Simon Willison, among the designers of Django) (works just with MySQL)
EDIT: Searching with the question linked by TokenMacGuy, I'll add two more towards the list with regard to completeness:
Simply to toss in an additional opinion - dmigrations is fairly nice obvious to make use of, but I'd say South is the best choice. Again, it's not hard to enter into, but it is more effective and has support for additional database backends than simply MySQL. It even handles MSSQL, if that is your factor