How to do syncdb in django 1.4.2? i.e. having data in database, how to load the models again when the data schema is updated?
Thanks in advance
How to do syncdb in django 1.4.2? i.e. having data in database, how to load the models again when the data schema is updated?
Thanks in advance
On
As you're using an older version of django you'll need to install the South module and make migrations for your apps.
To install South, you can use pip or easy_install
pip install South
Once you have the south module installed put it in your django projects settings' INSTALLED_APPS
INSTALLED_APPS = (
...
"south"
)
Then you'll need to make initial migrations first for your apps. So for an app named example you can run the command:
python manage.py makemigrations example --initial
python manage.py migrate
After the initial migration creation you make changes to your models and then make the new migrations and apply them.
python manage.py makemigrations example --auto
python manage.py migrate
Thanks Amyth for the hints.
btw the commands is a bit different, i will post a 10x tested result here.
Using south
1. setup the model
python manage.py schemamigration models --initialpython manage.py dumpdata -e contenttypes -e auth.Permission --natural > data.jsonpython manage.py syncdbpython manage.py migrate modelspython manage.py loaddata data.jsonpython manage.py schemamigration models --autopython manage.py migrate modelsafter every change you made in the models schema
A few notes
1. Unloading the database and reload it is essential, because if not doing so the first migration will tell you already have those models.
2. The
-e contenttypes -e auth.Permission --naturalparameter indumpdatais essential otherwise exception will be thrown when doing loaddata.