Home > Enterprise >  Make migrations is not detecting many to many field in model
Make migrations is not detecting many to many field in model

Time:03-31

Following are my models:

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)

No matter what i do, make migrations is not detecting this many to many field. Can someone please help?

CodePudding user response:

You put conversation: models.ManyToManyField(Message) instead of conversation=models.ManyToManyField(Message)

  • Related