According to
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey
I can define a foreign key to a model with a string if I haven't
defined the model yet.
The thing is, I'm not sure South is accounting for that.
I've got the following in a sample application in models.py:
__init__.pyc models.py tests.py
from django.db import models
# Create your models here.
class Object1(models.Model):
SomeText = models.TextField()
Object2 = models.ForeignKey("Object2")
class Object2(models.Model):
AnInt = models.IntegerField()
Now, when I run the initial migrations I get the following:
$ ./manage.py startmigration testapp --initial
Creating migrations directory at '/home/sneilan/webapps/goalcall/
myproject/../myproject/testapp/migrations'...
Creating __init__.py in '/home/sneilan/webapps/goalcall/myproject/../
myproject/testapp/migrations'...
+ Added model 'testapp.Object2'
+ Added model 'testapp.Object1'
Created 0001_initial.py.
$./manage migrate testapp
Running migrations for testapp:
- Migrating forwards to 0001_initial.
> testapp: 0001_initial
Traceback (most recent call last):
File "/home/sneilan/webapps/goalcall/myproject/south/migration.py",
line 243, in run_migrations
runfunc(klass.orm)
File "/home/sneilan/webapps/goalcall/myproject/../myproject/testapp/
migrations/0001_initial.py", line 21, in forwards
('SomeText', models.TextField()),
File "/home/sneilan/webapps/goalcall/myproject/south/db/generic.py",
line 121, in create_table
for field_name, field in fields
File "/home/sneilan/webapps/goalcall/myproject/south/db/generic.py",
line 272, in column_sql
sql = field.db_type()
File "/home/sneilan/webapps/goalcall/lib/python2.5/django/db/models/
fields/related.py", line 716, in db_type
rel_field = self.rel.get_related_field()
File "/home/sneilan/webapps/goalcall/lib/python2.5/django/db/models/
fields/related.py", line 609, in get_related_field
data = self.to._meta.get_field_by_name(self.field_name)
AttributeError: 'str' object has no attribute '_meta'
! Error found during dry run of migration! Aborting.
Whereas, if I take out the strings in the foreign key columns (and
reverse my objects), it works as expected.
Is there something I'm not doing right? I'm using the latest south
trunk. (I checked it out a couple hours earlier today.)