我已经看过这个主题下的stackoverflow问题,并且我将我的培训师类移到了我的类的上面,但是当我在命令提示符上输入“manage.py create superuser”时,仍然会得到相同的“name'Model'is not defined”错误。
此外,我正在艰难地迁移我的模型。我尝试了“django admin makemigrations training”,但django admin没有重新注册;以及“manage.py makemigrations training”,但makemigrations没有被识别。
如何迁移模型?
这是我的代码:
#from django.db import models
from django_pg import models
# Create your models here.
TRAINING_TYPE_CHOICES = (
('AC', 'Armed Combat'),
('UC', 'Unarmed Combat'),
('P', 'Piloting'),
('O', 'Other'),
)
GENDER_CHOICES = (
('F', 'Female'),
('M', 'Male'),
('U', 'Unspecified'),
)
OUTCOME_CHOICES = (
('P', 'Pass'),
('F', 'Fail'),
)
class Trainer(models, Model):
first_name = models.CharField(max_length = 25)
surname = models.CharField(max_length = 30)
address = models.CharField(max_length = 200)
gender = models.CharField(max_length = 1, choices = GENDER_CHOICES)
citizenship = models.CharField(max_length = 30)
email = models.EmailField(max_length = 30)
class Class_Training(models, Model):
trainer = models.ForeignKey('Trainer')
class_name = models.CharField(max_length = 30)
type_of_class = models.CharField(max_length = 2, choices= TRAINING_TYPE_CHOICES)
description = models.TextField(max_length = 200)
def __str__(self):
return self.class_name, self.trainer
class ReportLog(models.CompositeField):
class_ID = models.IntegerField
hero_ID = models.IntegerField
outcome = models.CharField(max_length = 1, choices = OUTCOME_CHOICES)
comments = models.TextField
trainer = models.IntegerField
class Meta:
db_type = 'report'
class Attendance(models.CompositeField):
class_ID = models.IntegerField
hero_ID = models.IntegerField
room_name = models.CharField(max_length = 30)
date = models.DateField
start_time = models.TimeField
end_time = models.TimeField
class Meta:
db_type = 'attendance'
class Room(models, Model):
room_name = models.CharField(max_length = 20)
class Hero(models, Model):
codename = models.CharField(max_length = 20)
def __str__(self):
return self.codename
用
解决问题Model
您在一些模型定义中使用了
models, Model
,而不是models.Model
。Model
类位于model
模块中。这就是为什么我们使用.
而不是逗号。房间型号:
英雄模式:
培训师型号:
最后:
解决迁移问题
应该是:
您需要
python
命令。还要检查您是否在manage.py
所在的目录中。相关问题 更多 >
编程相关推荐