Yep that was me. Thought I'd also post on the mailing list so that a
resolution would be documented here. Also wanted to see if anyone else
ran into this issue.
There seems to be an inconsistency on what South thinks the database
looks like versus the actual database schema. I'm not sure what
mechanism South is using to make decisions as to the database so not
sure where to start trailing the bug.
The error in essence is: South thinks changes I want it to migrate
have already been made. They are made in my models.py, a migration is
generated in South via --auto, ./manage.py migrate <<app>> is run,
then the errors tell me either the column already exists (for add
column operations) or that it can't find the column (for delete column
operations).
I've also tried to go step-by-step instead of using convert_to_south,
but I get the same errors.
Any help is appreciated. The annotated command line stdout of the
procedure and error is below
J
###### our database has data, but no South. We add 'south' to
INSTALLED_APPS then run:
ubuntu$ ./manage.py syncdb
Syncing...
Creating table south_migrationhistory
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> beans.login
> django.contrib.admin
> beans.markers
> south
Not synced (use migrations):
-
(use ./manage.py migrate to migrate these)
###### Now we run the convenience function 'convert_to_south' to get
us up to speed
ubuntu$ ./manage.py convert_to_south markers
Creating migrations directory at '/var/www/beans/../beans/markers/
migrations'...
Creating __init__.py in '/var/www/beans/../beans/markers/
migrations'...
+ Added model 'markers.Marker'
+ Added model 'markers.LinkageGroup'
+ Added model 'markers.URLReference'
+ Added model 'markers.GBrowse'
Created 0001_initial.py.
- Soft matched migration 0001 to 0001_initial.
Running migrations for markers:
- Migrating forwards to 0001_initial.
> markers: 0001_initial
(faked)
App 'markers' converted. Note that South assumed the application's
models matched the database
(i.e. you haven't changed it since last syncdb); if you have, you
should delete the markers/migrations
directory, revert models.py so it matches the database, and try again.
###### the model and the DB do match, so that's ok so far. Here we see
that the migration is in the db as normal
mysql> select * from south_migrationhistory;
+----+----------+--------------+---------------------+
| id | app_name | migration | applied |
+----+----------+--------------+---------------------+
| 1 | markers | 0001_initial | 2009-12-01 20:53:57 |
+----+----------+--------------+---------------------+
1 row in set (0.00 sec)
###### I now make a change to my markers/models.py, adding "ref_id =
m.IntegerField()", and save it. There are no other changes.
ubuntu$ ./manage.py startmigration markers add_ref_id --auto
+ Added field 'markers.marker.ref_id'
Created 0002_add_ref_id.py.
###### Just to be safe, let's look at the describe for our table in
question
mysql> describe markers_marker;
+------------------+--------------+------+-----+---------
+----------------+
| Field | Type | Null | Key | Default |
Extra |
+------------------+--------------+------+-----+---------
+----------------+
... bunch of columns, none of which is 'ref_id' ...
+------------------+--------------+------+-----+---------
+----------------+
###### No ref_id column, great! Now we try to migrate our markers app,
hitting this error
ubuntu$ ./manage.py migrate markers
Running migrations for markers:
- Migrating forwards to 0002_add_ref_id.
> markers: 0002_add_ref_id
Traceback (most recent call last):
File "/usr/local/lib/python2.6/site-packages/south/migration.py",
line 329, in run_migrations
runfunc(orm)
File "/var/www/beans/../beans/markers/migrations/
0002_add_ref_id.py", line 11, in forwards
db.add_column('markers_marker', 'ref_id', orm
['markers.marker:ref_id'])
File "/usr/local/lib/python2.6/site-packages/south/db/generic.py",
line 227, in add_column
self.execute(sql)
File "/usr/local/lib/python2.6/site-packages/south/db/generic.py",
line 86, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python2.6/site-packages/django/db/backends/
util.py", line 19, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.6/site-packages/django/db/backends/
mysql/base.py", line 84, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.2-
py2.6-linux-x86_64.egg/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.6/site-packages/MySQL_python-1.2.2-
py2.6-linux-x86_64.egg/MySQLdb/connections.py", line 35, in
defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1060, "Duplicate column name 'ref_id'")
! Error found during real run of migration! Aborting.
! Since you have a database that does not support running
! schema-altering statements in transactions, we have had to
! leave it in an interim state between migrations.
! You *might* be able to recover with:
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
On Dec 1, 5:37 am, Andrew Godwin <
and...@aeracode.org> wrote:
> I've already replied to something very similar to this on IRC, so it was
> probably you. For list posterity, it's logged athttp://
www.aeracode.org/logs/django-south/%23django-south_20091130.log, line