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
?
--run-syncdb. Allows creating tables for apps without migrations.
What is 'syncdb' syncdb is a command which is executed in django shell to create tables for first time for apps which are added to INSTALLED_APPS of settings.py. Need to keep in mind about two key words: 'First Time' and 'Newly Added Apps'.
In Django 1.9 onwards syncdb command is removed. So instead of use that one, you can use migrate command,eg: python manage.py migrate.Then you can run your server by python manage.py runserver command. Django has removed python manage.py syncdb command now you can simply use python manage.py makemigrations followed bypython manage.py migrate.
If you have multiple changes not applied yet django will run them in the correct order for you. You should definitely use migration system. Which lets you track changes in your models.py, and create migrations for the database. The migration system uses the commands makemigrations to create migrations and migrate to migrate the database.
For people trying to run Syncdb from Visual Studio 2015: The option syncdb was removed from Django 1.9 (deprecated from 1.7), but this option is currently not updated in the context menu of VS2015. Also, in case you didn't get asked to create a superuser you should manually run this command to create one: python.exe manage.py createsuperuser
If django is above 1.6, it has its own database migration process. And of course, if you use South to migrate, you have to use syncdb before executing migration, because if you don’t, initial database tables (including auth, auth_group_permission, django_admin_log etc) will not be created.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With