Михаил Шутов Михаил Шутов - 5 months ago 17
SQL Question

Django -> Cannot resolve keyword error, but field is in Choices in traceback

Migrate to new Django and I receive this error. My models:

class TourRoute(models.Model):
tour = models.ForeignKey(Tour, verbose_name=_(u'tour'), db_index=True)
country = models.ForeignKey(Country, verbose_name=_(u'country'),

class Tour(models.Model):
category = models.ForeignKey(TourCategory, verbose_name=_(u'tour type'),
null=True, blank=True)
kind = models.ForeignKey(TourKind, verbose_name=_(u'tour kind'), null=True,
blank=True, default=1)
tour_class = models.ForeignKey(TourClass, verbose_name=_(u'class'),
type = models.ForeignKey(TourType, verbose_name=_(u'tour type'),
null=True, blank=True)

In the views.py:

country_tours = Tour.objects.filter(tourroute__country__link=country.link)

In traceback django see this field (iraceback image):
Cannot resolve keyword 'tourroute' into field. Choices are: accommodation_note, ... tourroute, ...

I try:

  • adding related_name (tourroute changed in both traceback places to related_name value)

  • drop all tables and creating new database on MySQL/Postgersql

  • change replace my django (work in another project on the same server without this bug)

nothing helped ...

Help me please, before I broke my brain.

P.S. sorry for my English


Error found - one of apps overly imports in django

Thanks for the help!

UPD: this stings in old app version are the reason this bug:

options.Options._get_field = options.Options.get_field.im_func setattr(options.Options, 'get_field', get_field)