Modify

Ticket #160 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

validation error in convert_to_south

Reported by: akaihola Owned by: andrew
Priority: major Milestone: 0.6
Component: commands Version: 0.6-pre
Keywords: Cc:

Description

I have Django r10833, South r249 and the attached minimal Django project.

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

Attachments

south-accessor-clash-test-project.tar.gz (891 bytes) - added by akaihola 5 years ago.
minimal test project which produces the error

Change History

Changed 5 years ago by akaihola

minimal test project which produces the error

comment:1 Changed 5 years ago by akaihola

Using the trunk versions of Django and South, I ran convert_to_south, added a CharField to the Event model and automigrating didn't throw errors:

$ ./manage.py startmigration clash_app add_event_name --auto
 + Added field 'clash_app.event.name'
Created 0002_add_event_name.py.

comment:2 Changed 5 years ago by akaihola

Continuing by applying the migration works ok as well:

$ ./manage.py migrate 
Running migrations for clash_app:
 - Migrating forwards to 0002_add_event_name.
 > clash_app: 0002_add_event_name
   = ALTER TABLE "clash_app_event" ADD COLUMN "name" varchar(100) NOT NULL DEFAULT '(no name)'; []
 - Loading initial data for clash_app.

comment:3 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.6

comment:4 Changed 5 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed in [48f193b5cfcc].

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.