Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I use instead of syncdb in Django 1.9?

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?

like image 831
d33tah Avatar asked Apr 16 '15 18:04

d33tah


People also ask

What is run Syncdb?

--run-syncdb. Allows creating tables for apps without migrations.

What is Syncdb in Django?

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'.

How to run Django server using syncdb command?

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.

How do I migrate a Django database with multiple changes?

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.

Can't Run syncdb from Visual Studio 2015?

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

Why do I have to use syncdb before using south to migrate?

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.


1 Answers

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.

like image 140
tjati Avatar answered Oct 10 '22 16:10

tjati