[英]Django ManyToMany field is not created in model
Here is my Model for Teacher class. 这是我的老师课堂模型。
class Teacher(Profile):
class Meta:
db_table = 'teacher'
user = models.OneToOneField(User,
unique=True,
verbose_name=_('user'),
related_name='teacher')
home_address = models.CharField(_('home_address'), max_length=255, blank=True)
home_phone = models.CharField(_('home_phone'), max_length=30, blank=True)
cell_phone = models.CharField(_('cell_phone'), max_length=30, blank=True)
experience = models.IntegerField(default = 0)
summary = models.TextField(_('summary'), max_length=500, blank=True)
subjects = models.ManyToManyField(Subjects, through='SubjectsIntermediate')
When i execute the manage.py syncdb
it does creates the teacher
table with all fields except for field subjects
. 当我执行
manage.py syncdb
它会创建一个teacher
表,其中包含除字段subjects
以外的所有字段。 Why the subjects
field is not created?? 为什么没有创建
subjects
字段?
Because a ManyToMany isn't a field, at least not one that exists as a database column. 由于ManyToMany不是字段,因此至少没有一个作为数据库列存在。 It's a relationship with a linking table.
这是与链接表的关系。 You'll find that a table named
myapp_teacher_subjects
has been created, with foreign keys to both teacher and subjects. 您会发现已创建一个名为
myapp_teacher_subjects
的表,其中包含指向教师和学科的外键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.