运行 django South 时导入错误
我在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,有一些关于导入工作原理的背景知识:当您运行“
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 modulex.y
is executed, and then the interpreter pullsz
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 ofReview
, 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).或者只是模型及其文件不存在于您的环境中,但确实存在于您的配置中:)
(当我忘记“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...)