进行迁移未检测模型中的多对多字段

乘风 python 191

原文标题Make migrations is not detecting many to many field in model

以下是我的模型:

class Message(models.Model):
    sender = models.ForeignKey(
        to=Profile, on_delete=models.CASCADE, related_name="sender", null=True)  # This null is temporary will remove it
    receiver = models.ForeignKey(
        to=Profile, on_delete=models.CASCADE, related_name="receiver", null=True)  # This null is temporary will remove it
    text = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)

       
    def __str__(self):
        return self.text

    class Meta:
        ordering = ["timestamp"]


class Chat(models.Model):
    conversation: models.ManyToManyField(Message) #---> This field is not being detected.
    first_participant = models.ForeignKey(
        Profile, on_delete=models.CASCADE, related_name="first_participant")
    second_participant = models.ForeignKey(
        Profile, on_delete=models.CASCADE, related_name="second_participant")
    date_modified = models.DateTimeField(auto_now=True)

无论我做什么,进行迁移都不会检测到这个多对多的字段。有人可以帮忙吗?

原文链接:https://stackoverflow.com//questions/71686314/make-migrations-is-not-detecting-many-to-many-field-in-model

回复

我来回复
  • RedWheelbarrow的头像
    RedWheelbarrow 评论

    你把conversation: models.ManyToManyField(Message)而不是conversation=models.ManyToManyField(Message)

    2年前 0条评论