On Sat, 2009-04-11 at 18:56 -0700, nixon66 wrote: > I have a legacy database that I used inspectdb to create the models. > I cleaned up the models, set primary keys, foriegn keys etc. But when > I tried to create a view I get an "unknown column activity.fp_id_id > in field list". I'm not sure why its appending an extra id to the end > of a foriegnkey field. Here are the two models in question:
[...] > class Activity(models.Model): > activity_id = models.CharField(max_length=10, primary_key=True) > fp_id = models.ForeignKey(Clients, max_length=10, blank=True) This is where the problem is arising. ForeignKey objects at the Python level store an object. At the database level, they obviously don't do that and store a reference to the primary key (or some other unique field) in the related table. The normal way to convert the Python-level attribute to a database column name for related fields is to append an "_id" suffix. You have two choices here, one is to use the db_column attribute on the field to specify the column name. The probably better method is to name the attribute "fp" in the Django model. After all, it's *not* an id value, it's an object, so the current name, suggesting it's an id is a bit misleading. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---