Re: unknown column in field list
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 -~--~~~~--~~--~--~---
unknown column in field list
Forgot to add the view I'm using. def country_detail(request, country): c = Country.objects.get(slug=country) lobbyists = Activity.objects.filter(country=c) return render_to_response('country/country_detail.html', {'country':c, 'lobbyists':lobbyists}) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: unknown column in field list
oh, forgot to add the view I'm using. Here is the view. def country_detail(request, country): c = Country.objects.get(slug=country) lobbyists = Activity.objects.filter(country=c) return render_to_response('country/country_detail.html', {'country':c, 'lobbyists':lobbyists}) On Apr 11, 9:56 pm, nixon66 <nixon@gmail.com> 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 Clients(models.Model): > fp_id = models.CharField(max_length=10, primary_key=True) > fp_name = models.CharField(max_length=200, blank=True) > slug = models.CharField(max_length=200, blank=True) > reg_date = models.CharField(max_length=20, blank=True) > termination_date = models.CharField(max_length=20, blank=True) > address_is_foreign = models.CharField(max_length=2, blank=True) > address_1 = models.CharField(max_length=100, blank=True) > city = models.CharField(max_length=50, blank=True) > state = models.CharField(max_length=10, blank=True) > country = models.CharField(max_length=2, blank=True) > zipcode = models.CharField(max_length=10, blank=True) > foreign_cntry_represented = models.ForeignKey(Country, > max_length=2, blank=True) > class Meta: > db_table = u'clients' > > def __unicode__(self): > return self.country > > def get_absolute_url(self): > return 'lobby/client/%s/' % self.slug > > class Activity(models.Model): > activity_id = models.CharField(max_length=10, primary_key=True) > fp_id = models.ForeignKey(Clients, max_length=10, blank=True) > reg_id = models.ForeignKey(Lobbyist, max_length=10, blank=True) > supp_id = models.CharField(max_length=10, blank=True) > period_start_date = models.DateTimeField(null=True, blank=True) > period_end_date = models.DateTimeField(null=True, blank=True) > activity_type=models.ForeignKey > (Lobbytype,max_length=50,related_name="activity_type", blank=True) > slug = models.CharField(max_length=765, blank=True) > activity_desc = models.TextField(blank=True) > financial_amount = models.FloatField(null=True, blank=True) > financial_desc = models.TextField(blank=True) > country = models.CharField(max_length=2, primary_key=True) > year = models.CharField(max_length=5, blank=True) > class Meta: > db_table = u'activity' --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
unknown column in field list
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 Clients(models.Model): fp_id = models.CharField(max_length=10, primary_key=True) fp_name = models.CharField(max_length=200, blank=True) slug = models.CharField(max_length=200, blank=True) reg_date = models.CharField(max_length=20, blank=True) termination_date = models.CharField(max_length=20, blank=True) address_is_foreign = models.CharField(max_length=2, blank=True) address_1 = models.CharField(max_length=100, blank=True) city = models.CharField(max_length=50, blank=True) state = models.CharField(max_length=10, blank=True) country = models.CharField(max_length=2, blank=True) zipcode = models.CharField(max_length=10, blank=True) foreign_cntry_represented = models.ForeignKey(Country, max_length=2, blank=True) class Meta: db_table = u'clients' def __unicode__(self): return self.country def get_absolute_url(self): return 'lobby/client/%s/' % self.slug class Activity(models.Model): activity_id = models.CharField(max_length=10, primary_key=True) fp_id = models.ForeignKey(Clients, max_length=10, blank=True) reg_id = models.ForeignKey(Lobbyist, max_length=10, blank=True) supp_id = models.CharField(max_length=10, blank=True) period_start_date = models.DateTimeField(null=True, blank=True) period_end_date = models.DateTimeField(null=True, blank=True) activity_type=models.ForeignKey (Lobbytype,max_length=50,related_name="activity_type", blank=True) slug = models.CharField(max_length=765, blank=True) activity_desc = models.TextField(blank=True) financial_amount = models.FloatField(null=True, blank=True) financial_desc = models.TextField(blank=True) country = models.CharField(max_length=2, primary_key=True) year = models.CharField(max_length=5, blank=True) class Meta: db_table = u'activity' --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Unknown column in field list
On Wed, 2009-03-11 at 13:55 -0700, mike171562 wrote: > Hello, I tried to add a column to one of my models named Ticket. I ran > a syncdb with no errors, but when i load my app I get the following > error. If you change a model that already exists in the database, "syncdb" will not do anything. You either have to add the column manually to the database table or use one of the various migration tools around (e.g. django-evolution, south, dbmigrations) > > > (1054, "Unknown column 'tickets_ticket.ext_email' in 'field list'"). > > I tried dropping my Database and recreating to no avail. Anyone know > about this error. I'm surprised it didn't go away after recreating the database. That doesn't sound right. Can you create a small example of the model that demonstrates the problem (e.g. remove all the columns except the one you're trying add and see if it happens again) and show us? 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 -~--~~~~--~~--~--~---
Unknown column in field list
Hello, I tried to add a column to one of my models named Ticket. I ran a syncdb with no errors, but when i load my app I get the following error. (1054, "Unknown column 'tickets_ticket.ext_email' in 'field list'"). I tried dropping my Database and recreating to no avail. Anyone know about this error. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---