django 和 postgres 出现间歇性数据库错误:django 有时会尝试查询我几周前删除的数据库
我正在 django 中构建一个简单的 Web 应用程序,在开发中使用 sqlite,并在生产中运行 postgres。在我的本地服务器上一切正常,但我在生产方面遇到了一个奇怪的错误。
该错误影响了网站的多个部分,但最明显的例子是在管理页面上。有时,当我去检查句子表中的条目时,我会收到此错误:
DatabaseError at /admin/treeLing_app/sentence/
column treeLing_app_sentence.sexp does not exist
LINE 1: ...ce"."comment_id", "treeLing_app_sentence"."text", "treeLing_...
^
令人困惑的是,sexp(“s-表达式”)字段仅包含在数据库设计的早期版本中。代码中没有留下任何痕迹。从那时起,我还删除并重新创建了开发和生产数据库。
底线:我不知道 django/postgres 是如何知道旧的 sexp 字段的。最重要的是,我不明白为什么错误只是偶尔出现。 django 的 ORM 魔力似乎出现了严重错误。谁能为我解开这个谜团吗?
其他一些可能有用的细节:
- 当错误发生时,它往往会连续发生几次——就好像数据库进入另一种模式几分钟一样。
- 在网站的其他部分,该错误的表现有所不同。当模板引用句子对象中的字段时,这些字段只是空白。我很难调试这个问题,因为问题只在某些时候出现,而且我无法在我的开发计算机上复制它。
- postgres 是版本 9.1.1;我正在使用 psycopg2。
- 我用的是南航但正如我之前所说,自从问题出现以来,我已经完全删除并重新创建了两个数据库以及所有迁移,因此我怀疑 South 是问题所在。
- 我在 bitnami djangostack 上运行所有这些。不知道为什么这会产生任何影响,但你永远不知道......
感谢您的帮助!
编辑:一些新信息:经过多次测试,在使用 django 的 ./manage.py runserver 命令时,我无法在生产服务器上复制错误 - 该错误似乎仅在以下情况下发生使用 apache/wsgi 服务器。
这似乎缩小了问题范围。对于进一步追踪有什么建议吗?
I'm building a simple web application in django, using sqlite in development, and running postgres in production. Everything works fine on my local server, but I've run into a strange error on the production side.
The bug affects several parts of the site, but the clearest example is on the admin page. Sometimes when I go to inspect entries in the Sentence table, I get this error:
DatabaseError at /admin/treeLing_app/sentence/
column treeLing_app_sentence.sexp does not exist
LINE 1: ...ce"."comment_id", "treeLing_app_sentence"."text", "treeLing_...
^
The confusing thing about this is that the sexp (for "s-expression") field was only included in the very early versions of the database design. There's no trace of it left in the code. I've also dropped and re-created the development and production databases since then.
Bottom line: I can't figure out how django/postgres even knows about the old sexp field. On top of that, I don't understand why the error only pops up occasionally. It seems as though something has gone deeply wrong with the magic that is django's ORM. Can anyone solve this mystery for me?
A few other details that might be useful:
- When the error occurs, it tends to happen several times in a row -- as if the DB goes into another mode for a few minutes.
- In other parts of the site, the bug manifests differently. When templates reference fields in sentence objects, the fields are simply blank. I've had a hard time debugging this because the problem only shows up some of the time, and I haven't been able to replicate it on my development machine.
- postgres is version 9.1.1; I'm using psycopg2.
- I'm using South. But as I said earlier, I've completely dropped and recreated both databases--along with all migrations--since the problem began, so I doubt South is the problem.
- I'm running all this on the bitnami djangostack. Not sure why that would make any difference, but you never know...
Thanks for your help!
EDIT: Some new info: after much testing, I haven't been able to replicate the error on the production server when using django's ./manage.py runserver command -- the error only seems to happen when using the apache/wsgi server.
This seems to narrow down the problem. Any suggestions for tracking it down further?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果所有南方迁移都已成功应用(您没有 --fake 任何一个,是吗?),我想您可能有一个从模型的旧状态遗留下来的已编译的 .pyc 文件。在项目根目录尝试以下操作:
If all the South migrations have been applied successfully (you didn't --fake any of them, did you?), I guess it's possible you have a compiled .pyc file left over from the older state of the models. Try the following at the project root:
答案很愚蠢——重新启动 apache 和 postgresql。多么美好的一天啊。
The answer is silly -- restart apache and postgresql. What a day.