仅在 MySQL 数据库上出现 Django 错误
在本地我使用 sqllite3 作为数据库,但在生产中我使用 MySQL。当我将项目转移到生产环境时,我遇到了这个错误:
...
File "S:\Python27\lib\site-packages\django\templatetags\i18n.py", line 46, in
render
langs = self.languages.resolve(context)
File "S:\Python27\lib\site-packages\django\template\base.py", line 653, in res
olve
value = self._resolve_lookup(context)
File "S:\Python27\lib\site-packages\django\template\base.py", line 692, in _re
solve_lookup
raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current
)) # missing attribute
VariableDoesNotExist: Failed lookup for key [LANGUAGES] in u'[{}, {}, {}]'
我正在使用 django 的 i18n
关于这是从哪里来的有什么想法吗?谷歌没有提供太多信息,还有哪些数据对调试有用?我将本地测试环境指向生产数据库并得到相同的错误。
我在 settings.py 中的语言变量是:
LANGUAGES = (
('en',gettext('English')),
('fr',gettext('French')),
)
编辑 打开调试后,我收到错误:
Caught OperationalError while rendering: (1242, 'Subquery returns more than 1 row')
在 {% for f inframes %}
行上,
我的框架模型是:
@I18n('title','description')
class Collection(models.Model):
title = models.CharField(max_length=255)
description = models.CharField(max_length=255)
order = models.IntegerField(default=100)
image = models.ImageField(upload_to="collection/images",null=True)
rollover = models.ImageField(upload_to="collection/images",null=True,blank=True)
publish = models.BooleanField(default=True)
def __unicode__(self):
return self.title
@I18n('title')
class Frame(models.Model):
title = models.CharField(max_length=255)
collection = models.ManyToManyField(Collection)
order = models.IntegerField(default=100)
image = models.ImageField(upload_to="frame/images")
rollover = models.ImageField(upload_to="frame/images",null=True,blank=True)
publish = models.BooleanField(default=True)
def __unicode__(self):
return self.title
EDIT #2
麻烦的 MySQL 行,这并不' SQLite 中不会失败
SELECT `FrontEnd_article`.`id`, `FrontEnd_article`.`title_fr`, `FrontEnd_article`
.`title_en`, `FrontEnd_article`.`text_fr`, `FrontEnd_article`.`text_en`,
`FrontEnd_article`.`date`, `FrontEnd_article`.`image`, `FrontEnd_article`.`image_text`,
`FrontEnd_article`.`can_comment`, `FrontEnd_article`.`order`,
`FrontEnd_article`.`publish` FROM `FrontEnd_article` INNER JOIN
`FrontEnd_article_frames` ON (`FrontEnd_article`.`id` =
`FrontEnd_article_frames`.`article_id`) WHERE `FrontEnd_article_frames`.`frame_id` =
(SELECT U0.`id` FROM `FrontEnd_frame` U0 INNER JOIN `FrontEnd_frame_collection` U1 ON
(U0.`id` = U1.`frame_id`) WHERE (U1.`collection_id` = 1 AND U0.`publish` = True ))
ORDER BY `FrontEnd_article`.`date` DESC
再次感谢您的帮助!
Locally I use sqllite3 as a database, but in production I use MySQL. When I moved my project to production I encountered this error:
...
File "S:\Python27\lib\site-packages\django\templatetags\i18n.py", line 46, in
render
langs = self.languages.resolve(context)
File "S:\Python27\lib\site-packages\django\template\base.py", line 653, in res
olve
value = self._resolve_lookup(context)
File "S:\Python27\lib\site-packages\django\template\base.py", line 692, in _re
solve_lookup
raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current
)) # missing attribute
VariableDoesNotExist: Failed lookup for key [LANGUAGES] in u'[{}, {}, {}]'
I'm using django's i18n
Any ideas on where this is coming from? Google didn't inform much, also what data would be useful to look at for debugging? I pointed my local test environment to the production DB and got the same error.
My LANGUAGES var in settings.py is:
LANGUAGES = (
('en',gettext('English')),
('fr',gettext('French')),
)
EDIT
With debug turned on I get the error:
Caught OperationalError while rendering: (1242, 'Subquery returns more than 1 row')
on the line {% for f in frames %}
My Frame model is:
@I18n('title','description')
class Collection(models.Model):
title = models.CharField(max_length=255)
description = models.CharField(max_length=255)
order = models.IntegerField(default=100)
image = models.ImageField(upload_to="collection/images",null=True)
rollover = models.ImageField(upload_to="collection/images",null=True,blank=True)
publish = models.BooleanField(default=True)
def __unicode__(self):
return self.title
@I18n('title')
class Frame(models.Model):
title = models.CharField(max_length=255)
collection = models.ManyToManyField(Collection)
order = models.IntegerField(default=100)
image = models.ImageField(upload_to="frame/images")
rollover = models.ImageField(upload_to="frame/images",null=True,blank=True)
publish = models.BooleanField(default=True)
def __unicode__(self):
return self.title
EDIT #2
The troublesome MySQL lines, that doesn't fail in SQLite
SELECT `FrontEnd_article`.`id`, `FrontEnd_article`.`title_fr`, `FrontEnd_article`
.`title_en`, `FrontEnd_article`.`text_fr`, `FrontEnd_article`.`text_en`,
`FrontEnd_article`.`date`, `FrontEnd_article`.`image`, `FrontEnd_article`.`image_text`,
`FrontEnd_article`.`can_comment`, `FrontEnd_article`.`order`,
`FrontEnd_article`.`publish` FROM `FrontEnd_article` INNER JOIN
`FrontEnd_article_frames` ON (`FrontEnd_article`.`id` =
`FrontEnd_article_frames`.`article_id`) WHERE `FrontEnd_article_frames`.`frame_id` =
(SELECT U0.`id` FROM `FrontEnd_frame` U0 INNER JOIN `FrontEnd_frame_collection` U1 ON
(U0.`id` = U1.`frame_id`) WHERE (U1.`collection_id` = 1 AND U0.`publish` = True ))
ORDER BY `FrontEnd_article`.`date` DESC
Thanks again for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果暂时启用DEBUG,回溯是否相同?禁用时,错误消息可能会产生误导。这也可能是一个错误的数据库设置,Django 在不同的阶段退出。
Is the traceback the same if you enable DEBUG temporarily? Error messages can be misleading when it is disabled. It could as well be a wrong database setting and Django bails out at a different stage.
这是 Django 生成的简化版本。当我分解这个查询时,我意识到内部联接假设只返回 1 个值:
实际上返回了一个数据结果集。一旦我找到它,修复就很简单,我用“IN”替换了“=”并且它工作正常。
This is the simplified version of what is generated by Django. When I broke down this query I realised that inner join assumes that only 1 value is returned from:
Which in fact returned a result set of data. The fix was simple once I found it, I replaced the "=" with an "IN" and it worked correctly.