Question

My Django app is raising a puzzling error when using a production served version (via Apache, and Nginx for static), that is not evident for the dev server version on localhost.

I have the models :

class AdaptationLibrary(models.Model):
    description = models.CharField( u'Description of adaptation',max_length=400,blank=True,null=True)
    name = models.CharField(u'Adaptation Name',max_length=60)
    applies_to = models.ManyToManyField(Archetype,related_name =u'archetype_adaptations',null=True,blank=True)
    adaptations = jsonfield.JSONField(u'adaptation library items', null=True, blank=True)
    def __unicode__(self):
        return self.name

and ..

class Archetype(models.Model):
    archetype = models.CharField(max_length=20, choices=ARCHETYPE_CHOICES,unique=True)
    archetype_family = models.CharField(max_length=60,choices=ARCHETYPE_FAMILY_CHOICES,null=True)
    replacement_cost_default = models.FloatField("Default complete asset replacement cost - ($)",null=True, blank=True)
    lifespan_default = models.FloatField("Default asset life (yrs)", null=True, blank=True)
    age_default = models.FloatField("Default age - (yrs)", null=True, blank=True)
    storage_time_default = models.FloatField("Default storage/retention time (hrs)", null=True, blank=True)
    def __unicode__(self):
        return self.archetype

when I attempt to retrieve related Archetype objects via :

library_archetypes = library_item.applies_to.all()

I get the following error :

FieldError: Cannot resolve keyword u'archetype_adaptations' into field.
Choices are: age_default, archetype, archetype_family, asset, cemlo2, id,
lifespan_default, new_dependency, replacement_cost_default, storage_time_default

Dev and local versions are using the same database, and apart from the call to the AdaptationLibrary ManyToManyField, the rest of the app functions fine.

Can anybody shed some light on this issue?

Cheers

Edit: As per Rohan's suggestion that it's a migration problem - I've gone the whole box and dice of resetting and re-converting to south. Dev server is still happy - Apache served version throws same errors. Both versions are using the same DB.

(full traceback error) :

ERROR Traceback (most recent call last):

  File "C:\Python27\Lib\site-packages\dajaxice\core\DajaxiceRequest.py", line 181, in process
response = '%s' % thefunction(self.request, **argv)

  File "C:/Python27/sites/Adaptwater\proto4\ajax.py", line 2636, in populate_adaptation_library
initial_data = dict_to_library_form(library_item_id = library_to_load)

  File "C:/Python27/sites/Adaptwater\proto4\ajax.py", line 2556, in dict_to_library_form
library_archetypes = library_item.applies_to.all()

 File "C:\Python27\Lib\site-packages\django\db\models\manager.py", line 116, in all
return self.get_query_set()

  File "C:\Python27\Lib\site-packages\django\db\models\fields\related.py", line 543, in get_query_set
return super(ManyRelatedManager, self).get_query_set().using(db)._next_is_sticky().filter(**self.core_filters)

  File "C:\Python27\Lib\site-packages\django\db\models\query.py", line 621, in filter
return self._filter_or_exclude(False, *args, **kwargs)

  File "C:\Python27\Lib\site-packages\django\db\models\query.py", line 639, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))

  File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1250, in add_q
can_reuse=used_aliases, force_having=force_having)

  File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1122, in add_filter
process_extras=process_extras)

  File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1316, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))

FieldError: Cannot resolve keyword u'archetype_adaptations' into field. Choices are: age_default, archetype, archetype_family, asset, cemlo2, id, lifespan_default, new_dependency, replacement_cost_default, storage_time_default
Was it helpful?

Solution

Ok - sorry for the self answer, but I fixed the problem, even if I'm still mostly in the dark as to what caused it. After some additional serious googling, I found discussion about the problem in terms of ordering of imports, and model definitions both. For example :

http://chase-seibert.github.com/blog/2010/04/30/django-manytomany-error-cannot-resolve-keyword-xxx-into-a-field.html

After placing the AdaptationLibrary model ahead of Archetype in models.py (and quoting "Archetype" for m2m setup) it appears to be happy. Unless I'm missing something blindingly obvious, this feels like a voodoo fix. Up until now I'd been fastidiously putting referred to models before their referring buddies. But it's a fix nonetheless - so now back to work.

Cheers & Thanks.

OTHER TIPS

Try to use String instead of unicode...sometimes, I have had this problem where Apache is not able to understand UTF-8.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top