pythondjangodjango-modelsdjango-syncdb

How to do django syncdb in version 1.4.2?


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


Solution

  • 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

    1. dump data if you have to

    python manage.py dumpdata -e contenttypes -e auth.Permission --natural > data.json

    1. syncdb

    python manage.py syncdb
    python manage.py migrate models

    1. load the data back into the db

    python manage.py loaddata data.json

    1. Afterwards, you may use

    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.