我的一个应用程序中有一个模型,当我运行" python.py makemigrations注册时会抛出错误。"过去两天我花了很多文档(和谷歌)试图弄清楚为什么会发生这种错误。不幸的是,我什么都没有。
我想要做的是在我的项目中包含一个应用程序。该应用程序位于我的python目录的根目录中(不在我的项目的子文件夹中)。这是我的代码:
from django.db import models
class CompanyInfo(models.Model):
companyID = model.AutoField(primary_key=True)
companyName = model.CharField(max_length=100)
companyURL = model.URLField(max_length=100)
companyEmail = model.EmailField(max_length=254)
companyFEIN = model.CharField(max_length=50)
companyUsername= model.CharField(max_length=100)
companyPassword = model.CharField(max_length=100)
class CompanyContact(models.Model):
ccID = model.AutoField(primary_key=True)
ccFirstName = model.CharField(max_length=100)
ccLastName = model.CharField(max_length=100)
ccEmail = model.EmailField(max_length=254)
ccPhone = model.IntegerField(max_length=20)
打印到控制台的确切错误显示为:
root@ubuntu1204:/home/humanoid# python manage.py makemigrations humanoid
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/humanoid/signup/models.py", line 3, in <module>
class CompanyInfo(models.Model):
File "/home/humanoid/signup/models.py", line 4, in CompanyInfo
companyID = model.AutoField(primary_key=True)
NameError: name 'model' is not defined
答案 0 :(得分:3)
从导入看起来它应该是模型(复数)而不是模型。
答案 1 :(得分:3)
看起来你放弃了models
上的's'。您需要将model
的使用更改为models
。
例如:
companyID = model.AutoField(primary_key=True)
需要:
companyID = models.AutoField(primary_key=True)