Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: migrate Table 'forum_user' already exists

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")
like image 250
mike Avatar asked Feb 21 '12 07:02

mike


1 Answers

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.

like image 56
Yuji 'Tomita' Tomita Avatar answered Oct 12 '22 20:10

Yuji 'Tomita' Tomita