93๐
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.
64๐
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.
If for whatever reason you need to create a database the same way syncdb
did it there is command flag that causes migrate
to work the same way. You should only do this if you REALLY need it and you know what you are doing. For example to create an empty database on for a continuous integration system of your choice.
python manage.py migrate auth
# performs migrations for auth and contenttypes contrib apps
python manage.py migrate --run-syncdb
# creates the rest of the database
Tested on Django 1.9.1.
- [Django]-How to test Django's UpdateView?
- [Django]-Django โ "no module named django.core.management"
- [Django]-Celery. Decrease number of processes
9๐
You should use the makemigrations
and migrate
commands that were introduced in django 1.7
- [Django]-Django filter on the basis of text length
- [Django]-Difference between auto_now and auto_now_add
- [Django]-Django JSONField inside ArrayField
3๐
syncdb
has some problem with db migration. so, after django 1.7 makemigrations
and migrate
have been introduced.
Now in django 1.9 syncdb
has been deprecated.
try
1. python manage.py makemigrations
which detects changes in db and creates one .py
file as inside migrations folder
2. python manage.py migrate
will apply the migrations to the database
- [Django]-Django TextField and CharField is stripping spaces and blank lines
- [Django]-Django reverse lookup of foreign keys
- [Django]-How to produce a 303 Http Response in Django?