Just been updating to Django 1.3 and come across an odd error. I'm getting the following error from some code which works with version 1.2.7.
刚刚更新到Django 1.3并遇到了一个奇怪的错误。我从一些适用于1.2.7版本的代码中收到以下错误。
FieldError: Cannot resolve keyword 'email_config_set' into field. Choices are: id, name, site, type
The odd thing being email_config_set is a related name for a ManyToMany field. I'm not sure why django is trying to resolve it into a field.
奇怪的是email_config_set是ManyToMany字段的相关名称。我不确定为什么django试图把它解决到一个领域。
The error occurs deep inside django:
错误发生在django内部:
Traceback (most recent call last):
File "./core/driver.py", line 268, in run
self.init_norm()
File "./driver/emailevent/background.py", line 130, in init_norm
self.load_config()
File "./driver/emailevent/background.py", line 71, in load_config
events = list(config.events.select_related())
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/manager.py", line 168, in select_related
return self.get_query_set().select_related(*args, **kwargs)
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/fields/related.py", line 497, in get_query_set
return superclass.get_query_set(self).using(db)._next_is_sticky().filter(**(self.core_filters))
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/query.py", line 550, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/query.py", line 568, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/sql/query.py", line 1194, in add_q
can_reuse=used_aliases, force_having=force_having)
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/sql/query.py", line 1069, in add_filter
negate=negate, process_extras=process_extras)
File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/sql/query.py", line 1260, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'email_config_set' into field. Choices are: id, name, site, type
Any pointers or tips would be welcome.
任何指针或提示都会受到欢迎。
1 个解决方案
#1
1
The problem in this case was due to dynamic models, and their creation order. More specifically, some models which were dynamically created after others, were not defined when the _meta caches were filled, and therefore lead to errors. Clearing the caches or changing the creation order resolves this problem.
这种情况下的问题是由于动态模型及其创建顺序。更具体地说,在填充_meta缓存时未定义一些在其他模型之后动态创建的模型,因此导致错误。清除缓存或更改创建顺序可以解决此问题。
See also https://groups.google.com/d/msg/django-users/RJlV5_ribZk/P6tv4QlJN4EJ
另请参阅https://groups.google.com/d/msg/django-users/RJlV5_ribZk/P6tv4QlJN4EJ
#1
1
The problem in this case was due to dynamic models, and their creation order. More specifically, some models which were dynamically created after others, were not defined when the _meta caches were filled, and therefore lead to errors. Clearing the caches or changing the creation order resolves this problem.
这种情况下的问题是由于动态模型及其创建顺序。更具体地说,在填充_meta缓存时未定义一些在其他模型之后动态创建的模型,因此导致错误。清除缓存或更改创建顺序可以解决此问题。
See also https://groups.google.com/d/msg/django-users/RJlV5_ribZk/P6tv4QlJN4EJ
另请参阅https://groups.google.com/d/msg/django-users/RJlV5_ribZk/P6tv4QlJN4EJ