I'm trying to use the same foreign key for two fields in the same model and am getting an error.
Im trying to have a primary and secondary on call user, but am not sure how to format the relationship after receiving the errors below
class ManualRotas(models.Model):
rota_name = models.CharField(max_length=200,choices=settings.ONCALL_ROTAS)
primary_user = models.ForeignKey(User, unique=True, verbose_name="Primary OnCall Engineer")
p_start_time = models.DateTimeField(verbose_name="Start Time")
p_end_time = models.DateTimeField(verbose_name="End Time")
secondary_user = models.ForeignKey(User, verbose_name="Backup OnCall Engineer", unique=True,blank=True,null=True)
s_start_time = models.DateTimeField(blank=True,null=True, verbose_name="Start Time")
s_end_time = models.DateTimeField(blank=True,null=True,verbose_name="Start Time")
ERRORS:
oncall.ManualRotas.primary_user: (fields.E304) Reverse accessor for 'ManualRotas.primary_user' clashes with reverse accessor for 'ManualRotas.secondary_user'.
HINT: Add or change a related_name argument to the definition for 'ManualRotas.primary_user' or 'ManualRotas.secondary_user'.
oncall.ManualRotas.secondary_user: (fields.E304) Reverse accessor for 'ManualRotas.secondary_user' clashes with reverse accessor for 'ManualRotas.primary_user'.
HINT: Add or change a related_name argument to the definition for 'ManualRotas.secondary_user' or 'ManualRotas.primary_user'.
WARNINGS:
oncall.ManualRotas.primary_user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
oncall.ManualRotas.secondary_user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
System check identified 4 issues (0 silenced).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…