Django syncdb and updated model

I recently updated my model by adding a BooleanField to it, but when I do python manage.py syncdb it does not add a new field to the database for the model. How can i fix this?

+84
python django django-models
Oct 22 '09 at 8:04
source share
7 answers

Starting from Django 1.7 onwards

Django supports migration - see the documentation .

For Django 1.6 and earlier

Django does not support migration out of the box. Django has a plug-in application that works that way, and it works great. It is called South .

+100
Oct 22 '09 at 8:09
source share

Django does not currently do this automatically. Your options:

  • Drop the table from the database, and then recreate it in a new form using syncdb.
  • Print the SQL for the database using python manage.py sql (appname) , find the added row for the field and add it manually using the alter table SQL command. (This will also allow you to select field values ​​for your current records.)
  • Use South (for Dominic's answer ).
+14
Oct 22 '09 at 8:11
source share

Follow these steps:

  • Export your data to the instrument using the dumpdata command
  • Drop the table
  • Run syncdb
  • Reload the data from the device using the loaddata command
+11
Oct 22 '09 at 8:15
source share

As suggested in the top answer, I tried to use South and after an hour of disappointment, unclear migration errors decided to go instead of Django Evolution .

It seems to me that it is easier to start work from the South, and it worked great the first time I typed ./manage.py evolve --hint --execute , so I am pleased with this.

+8
May 25 '11 at 15:57
source share

Havent used django at the time, but I seem to remember that syncdb executes alter commands on db tables. you need to drop the table and run it again, and it will be created again.

edit: sorry DOES NOT execute alter.

+2
Oct 22 '09 at 8:08
source share

If you are running Django with Apache and MySQL, restart apache after migration using makemigrations.

0
Dec 26 '14 at 1:22
source share

In django 1.6

  • First we did - python manage.py sql <app name>

  • Then we need to run - python manage.py syncdb

0
May 13 '16 at 5:49 a.m.
source share



All Articles