Reputation: 532
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
Upvotes: 1
Views: 3067
Reputation: 532
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 --initial
python manage.py dumpdata -e contenttypes -e auth.Permission --natural > data.json
python manage.py syncdb
python manage.py migrate models
python manage.py loaddata data.json
python manage.py schemamigration models --auto
python manage.py migrate models
after 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 --natural
parameter in dumpdata
is essential otherwise exception will be thrown when doing loaddata.
Upvotes: 3
Reputation: 32969
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
Upvotes: 6