Ticket #105 (closed defect: fixed)

Opened 7 years ago

Last modified 4 years ago

ForeignKey relationships that specify their 'to' model as a string fail

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



my_field = models.ForeignKey?('app.TableName?')

When migrate is run:

File "south/db/generic.py", line 121, in create_table

for field_name, field in fields

File "south/db/generic.py", line 272, in column_sql

sql = field.db_type()

File "/usr/lib/python2.5/site-packages/django/db/models/fields/related.py", line 708, in db_type

rel_field = self.rel.get_related_field()

File "/usr/lib/python2.5/site-packages/django/db/models/fields/related.py", line 601, in get_related_field

data = self.to._meta.get_field_by_name(self.field_name)

AttributeError?: 'str' object has no attribute '_meta'

Change History

comment:1 Changed 7 years ago by andrew

  • Status changed from new to accepted
  • Milestone set to 0.5

comment:2 Changed 7 years ago by andrew

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

So, the basic DB API of South can't accept strings for a good reason (we can't logically infer from the string what version of the model you're referring to).

The best fix I can do is [189] - startmigration now replaces strings with orm.Foo or ormapp.Bar? where it can.

Note: See TracTickets for help on using tickets.