我的 Django 应用程序在使用生产服务版本(通过 Apache 和静态 Nginx)时引发了一个令人费解的错误,这对于本地主机上的开发服务器版本并不明显。
我有模型:
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
和 ..
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
当我尝试通过以下方式检索相关的 Archetype 对象时:
library_archetypes = library_item.applies_to.all()
我收到以下错误:
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
开发版本和本地版本使用相同的数据库,除了调用 AdaptationLibrary ManyToManyField 之外,应用程序的其余部分功能正常。
任何人都可以对这个问题有所了解吗?
干杯
编辑:根据 Rohan 的建议,这是一个迁移问题 - 我已经完成了重置和重新转换到南方的整个盒子和骰子。开发服务器仍然很高兴 - Apache 服务的版本会引发相同的错误。两个版本都使用相同的数据库。
(完整的回溯错误):
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