我正在尝试将我的Django模型拆分为单独的文件,但我显然没有做对。当我尝试运行自从我开始项目以来我一直使用的Django脚本时,我得到了这个:
$ ./import.py
Traceback (most recent call last):
File "./import.py", line 6, in <module>
from mcif.models import GenericImport, CSVRow
File "/home/jason/projects/mcifdjango/mcif/models/__init__.py", line 1, in <module>
from mcif.models.account_address import AccountAddress
File "/home/jason/projects/mcifdjango/mcif/models/account_address.py", line 1, in <module>
class AccountAddress(models.Model):
NameError: name 'models' is not defined
我的应用名为mcif
,它正在讨论mcif/models/account_address.py
,这就是:
class AccountAddress(models.Model):
id = models.BigIntegerField(primary_key=True)
account = models.ForeignKey(Account)
address = models.ForeignKey(Address)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
class Meta:
db_table = u'account_address'
app_name = 'mcif'
它说它不知道models
的{{1}}部分,这是有道理的。我假设我需要导入一些东西,但如果是这种情况,我不知道要导入什么。如果情况并非如此,那我就完全失去了。我该怎么办?
答案 0 :(得分:3)
account_address.py中是否有from django.db import models
?