南迁错误 - 已经存在 [英] South migrate error - relation already exists

查看:125
本文介绍了南迁错误 - 已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:
添加djangoratings到我的项目后,我尝试运行

Background: After adding djangoratings to my project, I tried running

django-admin.py schemamigration djangoratings --initial 
--settings=myapp.settings.local 

导致未知模式迁移的命令错误。
我尝试通过将我的项目目录添加到PYTHONPATH来解决此错误(我使用的是virtualenv和virtualenvwrapper)。
这解决了schemamigration的未知命令错误,但是我想我在PYTHONPATH的项目目录上面指定了一个目录,当初始迁移运行时,它会抱怨与whoosh(我正在使用的)在我的项目中)。我更改了PYTHONPATH目录并尝试运行

which resulted in an unknown command error for schemamigration. I tried to resolve this error by adding my project directory to the PYTHONPATH (I'm using virtualenv and virtualenvwrapper). This resolved the unknown command error for schemamigration, but I think I specified one directory above my project directory for the PYTHONPATH and when the initial migration was run for djangoratings, it complained about something to do with whoosh (which I am using in my project). I changed the PYTHONPATH directory and tried running

django-admin.py schemamigration djangoratings --initial 
--settings=myapp.settings.local

再次。然后我运行migrate命令。这是当我收到错误:

again. Then I ran the migrate command. This is when I received the error:

django.db.utils.DatabaseError: relation "djangoratings_vote" already exists

我尝试使用以下方式一直迁移:

I tried migrating all the way back using:

django-admin.py migrate djangoratings zero --settings=myapp.settings.local
Running migrations for djangoratings:
- Migrating backwards to zero state.
< djangoratings:0006_add_cookies
< djangoratings:0005_add_exclusions
< djangoratings:0004_rethink_recommendations
< djangoratings:0003_add_correlations
< djangoratings:0002_add_mean_and_stddev
< djangoratings:0001_initial

然后再次运行--initial,但执行迁移命令后发生相同的错误。

and then running --initial again, but the same error occurred after performing the migrate command.

我查看了数据库中的表格列表,没有看到任何djangoratings_vote。

I looked at the list of tables in my database and didn't see any for djangoratings_vote.

我目前的迁移列表如下:

My current migrations listing for djangoratings is as follows:

0001_initial.py                   0006_add_cookies.py
0001_initial.pyc                  0006_add_cookies.pyc
0002_add_mean_and_stddev.py       0007_initial.py
0002_add_mean_and_stddev.pyc      0007_initial.pyc
0003_add_correlations.py          0008_initial.py
0003_add_correlations.pyc         0008_initial.pyc
0004_rethink_recommendations.py   0009_initial.py
0004_rethink_recommendations.pyc  0009_initial.pyc
0005_add_exclusions.py            __init__.py
0005_add_exclusions.pyc           __init__.pyc

如何解决关系djangoratings_vote已经存在错误?最好使用南方?

How can I resolve the relation "djangoratings_vote" already exists error? Preferably using South?

推荐答案

听起来好像南方与你的数据库不同步(如果南方已经开始创建表,但是无法完成向后迁移,则失败)。我建议手动恢复数据库和南方如下(如果出现错误,请先备份您的数据库):

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. 删除您的数据库中的所有djangoratings_ *表。

  2. 打开数据库中的south_migrationhistory表,并按应用名称过滤。删除djangoratings的所有条目。

  3. 删除djangoratings / migrations目录中的所有迁移文件。

一旦你这样做,你应该有一个干净的数据库和南部的历史。此时,重新运行:

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.

假设你没有得到你第一次出现的错误,应该设置数据库,因此您可以使用django评级。

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.

这篇关于南迁错误 - 已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆