Background: After adding djangoratings to my project, I tried running
django-admin.py schemamigration djangoratings --initial
--settings=myapp.settings.local
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
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
and then running --initial again, but the same error occurred after performing the migrate command.
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
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):
Once you have done this, you should have a clean database, and south history. At this point, re run:
Which will generate a single migration file. Then:
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.
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
there is a better way to solve it:
and then: