What should I use instead of syncdb in Django 1.9?

d33tah picture d33tah · Apr 16, 2015 · Viewed 83.4k times · Source

Take a look at this:

$ pypy ./manage.py syncdb
/usr/lib64/pypy-2.4.0/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
  warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)

(cut)

I ran a quick google search, but could not find the answer - what should I be using instead of syncdb?

Answer

tjati picture tjati · Apr 16, 2015

syncdb is deprecated because of the migration system, introduced with django 1.7.

Now you can track your changes using makemigrations. This transforms your model changes into python code to make them deployable to another databases. When you have further modifications you need applied to the database, you can use data migrations.

After you created the migrations you have to apply them: migrate.

So instead of using syncdb you should use makemigrations and then migrate.

Workflow on development after you changed something in your models:

./manage.py makemigrations
./manage.py migrate

And on your production system:

./manage.py migrate

Bonus: you do not need to run migrate for each change. If you have multiple changes not applied yet django will run them in the correct order for you.