我的代码如下所示:
class X(models.Model):
class Meta:
db_table = 'X'
ph_no = models.CharField(max_length =255,null=False)
y = models.ForeignKey('y',on_delete=models.CASCADE)
class M(models.Model):
class Meta:
db_table = 'M'
comment = models.CharField(max_length=255,null= False)
x = models.ForeignKey('X',on_delete=models.CASCADE)
class y (models.Model):
class Meta:
db_table = 'y'
details = models.TextField(null= False)
现在,使用此架构运行迁移时,我收到以下错误
appName.M.x: (fields.E300) Field defines a relation with model 'X', which is either not installed, or is abstract.
appName.M.x: (fields.E307) The field appName.M.x was declared with a lazy reference to 'appName.X', but app 'appName' doesn't provide model 'X'.
我的settings.py文件如下:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'dashboard'
]
答案 0 :(得分:0)
已安装的应用
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
*'dashboard'*
with
'dashboard.apps.DashboardConfig'
]
仪表板应用程序中的和apps.py
from django.apps import AppConfig
class DashboardConfig(AppConfig): name ='dashboard'