Tuesday, February 28, 2012

Problem creating foreign key on a model created by inspectdb

I have a legacy database from which I created a model called 'LandSupplier'

class LandSupplier(models.Model):
landsupplierid = models.AutoField(primary_key=True,
db_column='LandSupplierId') # Field name made lowercase.
...
class Meta:
db_table = u'LandSupplier'
ordering = ("name",)

I have a second model called LandOffer:

class LandOffer(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=300, db_column='Name') #
Field name made lowercase.
supplier = models.ForeignKey('LandSupplier', db_column='landsupplierid')

I get this error:

Request Method: GET
Request URL: http://localhost:8000/admin/land/landoffer/
Django Version: 1.3.1
Exception Type: OperationalError
Exception Value: (1054, "Unknown column
'land_landoffer.landsupplierid' in 'field list'")

It seems to take my fieldname, but not my table name. I'm wondering
how to fix this. I could rename the table to 'land_landoffer' but
that would mess up a lot of other code, and I would rather learn what
I am doing wrong here

--
Joel Goldstick

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment