Ticket #160 (closed defect: fixed)
validation error in convert_to_south
|Reported by:||akaihola||Owned by:||andrew|
I first create the tables:
$ ./manage.py syncdb --noinput Syncing... Creating table clash_app_location Creating table clash_app_event Creating table south_migrationhistory Installing index for clash_app.Event model Synced: > clash_app > south Not synced (use migrations): - (use ./manage.py migrate to migrate these)
Then try to convert clash_app to use South, which succeeds but spits out an ugly error:
$ ./manage.py convert_to_south clash_app Creating migrations directory at '/tmp/south_accessor_clash/clash_app/migrations'... Creating __init__.py in '/tmp/south_accessor_clash/clash_app/migrations'... + Added model 'clash_app.Location' + Added model 'clash_app.Event' Created 0001_initial.py. Error: One or more models did not validate: models.event: Accessor for field 'location' clashes with related field 'Location.event_set'. Add a related_name argument to the definition for 'location'.
If I use the old method instead, there's no error. First startmigration:
$ ./manage.py startmigration clash_app --initial Creating migrations directory at '/tmp/south_accessor_clash/clash_app/migrations'... Creating __init__.py in '/tmp/south_accessor_clash/clash_app/migrations'... + Added model 'clash_app.Location' + Added model 'clash_app.Event' Created 0001_initial.py.
Then migrate --fake:
$ ./manage.py migrate clash_app --fakeRunning migrations for clash_app: - Migrating forwards to 0001_initial. > clash_app: 0001_initial (faked)
I've verified that the contents of the resulting migrations directory are identical with both methods. I also tested the old method with Django 1.0.2 and South 0.5, and it works fine.
What causes the error in my test project is a combination of two things:
- the Location model is in its own module
- the confirmed field of the Event class has a default value
If both models are in models.py or models/__init__.py OR if there's no default value for the confirmed field, there's no error.
The condition for the validation error is tested in django/core/management/validation.py on line 99. The same validation method is called when manage.py validate is called, but that succeeds without an error:
$ ./manage.py validate 0 errors found