Django: migrate Table 'forum_user' already exists

mike picture mike · Feb 21, 2012 · Viewed 8.4k times · Source

I have changed the Django models, and I use the Django schemamigration to update the database. But, when I do python manager.py migrate app, it throws this error message:

_mysql_exceptions.OperationalError: (1050, "Table 'forum_user' already exists")

Answer

Yuji 'Tomita' Tomita picture Yuji 'Tomita' Tomita · Feb 21, 2012

Then the table that django south is trying to create already exists and doesn't match the state of your database.

If this is the first time you're migrating, remember that before you make schemamigration changes, you must set the initial state via schemamigration myapp --initial and migrate app --fake to match the database to the south database state.

manage.py convert_to_south myapp also does the above as a convenience method.

To start using south...

  1. Make sure your django tables match your current database tables exactly - if you planned to add or remove columns, comment those out.
  2. Run python manage.py schemamigration myapp --initial
  3. Run python manage.py migrate myapp --fake
  4. Make changes to your django model
  5. Run python manage.py schemamigration myapp --auto
  6. Run python manage.py migrate myapp

Update

Note django 1.7+ ships with migrations and south is no longer in use.

There are only two commands worth noting..

  • manage.py makemigrations (handles --initial)
  • manage.py migrate

Written by the same author as South, crowd funded. Go django.