运行 django South 时导入错误

发布于 2024-11-07 21:48:12 字数 504 浏览 4 评论 0原文

我在我的 facebook 用户和汽车评论之间添加了一个 ManyToMany 字段到 ./facebook/model.py ,这需要我插入:

from car.models import Review

我尝试运行:

./manage.py schemamigration facebook --auto

但我收到错误:

django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name Review

问题是,我的 facebook 应用程序与第三个无关派对干草堆模块。我尝试了一些简单的调试,发现只要我尝试导入 Review,就会出现错误。改不改模型都没关系。难道是我的“INSTALLED_APPS”的顺序?我有“汽车”,然后是“facebook”,然后是“haystack”。

I added a ManyToMany field between my facebook user and car Reviews to ./facebook/model.py which required me to insert:

from car.models import Review

I try to run:

./manage.py schemamigration facebook --auto

but i get error:

django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name Review

The problem is, my facebook app has nothing to do with the third party haystack module. I tried some simple debugging and found as long as i try to import Review, i get the error. It doesn't matter if I change the model or not. Could it be the order of my "INSTALLED_APPS"? I have "car" followed by "facebook" and then "haystack".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨敛清荷 2024-11-14 21:48:12

因此,有一些关于导入工作原理的背景知识:当您运行“from xy import z”之类的语句时,整个模块 xy 都会被执行,然后解释器会拉取z 并将其放置在您的命名空间中。

因此,您的根本问题可能与 South 或 Haystack 无关;它可能在 car.models 的某个地方。这就是为什么无论您如何遇到 Review 的导入,您都会收到错误,并且如果您尝试从该模块导入其他任何内容,您很可能会收到该错误。

检查 car.models 是否存在问题 - 特别是,您可能存在循环导入(换句话说,A 从 B 导入并且 B 从 A 导入的情况)。

So, a bit of background on how imports work: When you run a statement like "from x.y import z", the entire module x.y is executed, and then the interpreter pulls z and places it in your namespace.

So, your underlying problem probably has nothing to do with South or Haystack; it's probably in car.models somewhere. That's why you're getting an error no matter how you come across the importing of Review, and you'll likely get it if you try to import anything else from that module.

Check car.models for problems -- in particular, you might have a circular import (in other words, a case where A imports from B and B imports from A).

放赐 2024-11-14 21:48:12

或者只是模型及其文件不存在于您的环境中,但确实存在于您的配置中:)
(当我忘记“git add”文件夹并且构建到暂存后出现此错误时,发生在我身上......)

Or simply the model with its files does not exist in your environment but does exist in your configuration :)
(happened to me when I forgot to "git add" a folder and after building into staging got this error...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文