South migrate error - relation already exists

久未见 提交于 2019-12-01 02:54:06
Giles Smith

It sounds to me as if South is out of sync with your database (this can happen if south has started creating the tables, but then fails without being able to complete the backwards migration). I would recommend manually restoring the database and south as follows (take a back up of your db first in case of a mistake):

  1. Delete all djangoratings_* tables from your database.
  2. Open up the south_migrationhistory table in the database, and filter by app name. Remove all entries for djangoratings.
  3. Delete all the migrations files in the djangoratings/migrations directory.

Once you have done this, you should have a clean database, and south history. At this point, re run:

./manage.py schemamigration djangoratings --initial

Which will generate a single migration file. Then:

./manage.py migrate djangoratings.

Assuming that you don't get the errors that you had the first time, this should set up the database so you are ready to use django ratings.

there is a better way to solve it:

python manage.py migrate djangoratings --fake

and then:

python manage.py migrate

This is in an extension of @stef_huayue's answer if it does not quite work as expected.

Find out which migration failed. The coressponding migration_file.py will usually be where the migrations.AddField operation is happening. Then run: python manage.py migrate app_name --fake [migration_file]

without the file extension. Followed by:

python manage.py migrate app_name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!