django syncdb and an updated model

PythonDjangoDjango Models

Python Problem Overview


I have recently updated my model, added a BooleanField to it however when I do python manage.py syncdb, it doesn't add the new field to the database for the model. How can I fix this ?

Python Solutions


Solution 1 - Python

From Django 1.7 onwards

Django has built in support for migrations - take a look at the documentation.

For Django 1.6 and earlier

Django doesn't support migrations out of the box. There is a pluggable app for Django that does exactly that though, and it works great. It's called South.

Solution 2 - Python

Django currently does not do this automatically. Your options are:

  1. Drop the table from the database, then recreate it in new form using syncdb.
  2. Print out SQL for the database using python manage.py sql (appname), find the added line for the field and add it manually using alter table SQL command. (This will also allow you to choose values of the field for your current records.)
  3. Use http://south.aeracode.org/">South</a> (per https://stackoverflow.com/questions/1605662/django-syncdb-and-an-updated-model/1605673#1605673">Dominic's answer).

Solution 3 - Python

Follow these steps:

  1. Export your data to a fixture using the dumpdata management command
  2. Drop the table
  3. Run syncdb
  4. Reload your data from the fixture using the loaddata management command

Solution 4 - Python

As suggested in top answer, I tried using South, and after an hour of frustration with obscure migration errors decided to go with Django Evolution instead.

I think it's easier to get started with than South, and it worked perfectly the first time I typed ./manage.py evolve --hint --execute, so I'm happy with it.

Solution 5 - Python

Havent used django in a while, but i seem to remember that syncdb does perform alter commands on db tables. you have to drop the table then run again and it will create again.

edit: sorry does NOT perform alter.

Solution 6 - Python

In django 1.6

  • At first we have run - python manage.py sql <app name>

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

Solution 7 - Python

If you run Django with Apache and MySQL, restart apache after making migration with makemigrations.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHellnarView Question on Stackoverflow
Solution 1 - PythonDominic RodgerView Answer on Stackoverflow
Solution 2 - PythoncheView Answer on Stackoverflow
Solution 3 - PythonSoviutView Answer on Stackoverflow
Solution 4 - PythonDan AbramovView Answer on Stackoverflow
Solution 5 - PythonAlex HView Answer on Stackoverflow
Solution 6 - PythonMonwara Hossain MunniView Answer on Stackoverflow
Solution 7 - PythonFelipe PerryView Answer on Stackoverflow