使用Python 2.7.x + Django的1.9:新手Django的模型错误
我创建django-admin startproject simple
作为合法性检查的新超级简单的Django框架项目,我创建了一个views.py
文件用一个简单的观点输出一个“hello world”类型的测试消息和一个到该视图的url路由。我可以运行这与python manage.py runserver
,它工作正常。
我使用一个超级简单的Django ORM模型类创建了一个models.py
文件。仅供参考,我的目标是使用现有的表和模式,所以我不希望ORM生成新的表。
class SuperSimpleModel(models.Model):
some_value = models.CharField(blank=True, null=True)
class Meta:
managed = False
db_table = 'model_test_table'
仅仅增加import models
我views.py
代码会导致在服务器启动时发生与python manage.py runserver
以下错误:
"RuntimeError: Model class simple.models.SuperSimpleModel doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded."
我相信我的应用程序不正确初始化?我已将这个问题归结为上述简单的可重复步骤集。在上述步骤中我没有改变settings.py
中的任何内容。通常情况下,我需要配置数据库,但即使如此,我也可以重现错误。
尝试在配置文件INSTALLED_APPS中添加'SuperSimpleModel' – Zartch