我想在其中存储一些额外的信息,自动创建,ManyToMany join-table.我怎么在Django那样做?
在我的情况下,我有两个表:"员工"和"项目".我想要存储的是每个员工每个项目每小时工作收到多少,因为这些值不相同.那么,我该怎么做?
我遇到的是,而不是方法"ManyToManyField",显式创建第三个类/表来存储这些新信息,并使用"ForeignKey"方法设置与"Employees"和"Projects"的关系.我很确定它会起作用,但这是最好的方法吗?
我正在尝试将M2M字段修改为ForeignKey字段.命令validate显示没有问题,当我运行syncdb时:
ValueError: Cannot alter field xxx into yyy they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)
Run Code Online (Sandbox Code Playgroud)
所以我无法进行迁移.
class InstituteStaff(Person):
user = models.OneToOneField(User, blank=True, null=True)
investigation_area = models.ManyToManyField(InvestigationArea, blank=True,)
investigation_group = models.ManyToManyField(InvestigationGroup, blank=True)
council_group = models.ForeignKey(CouncilGroup, null=True, blank=True)
#profiles = models.ManyToManyField(Profiles, null = True, blank = True)
profiles = models.ForeignKey(Profiles, null = True, blank = True)
Run Code Online (Sandbox Code Playgroud)
这是我的第一个Django项目,所以欢迎任何建议.