Reputation: 31
class Chellenge(models.Model):
sno = models.AutoField(primary_key=True, default="1",null=False)
chellengeName = models.CharField(max_length=50, blank=False, null=False)
chellengeDesc = models.TextField(max_length=1000, blank=True, null=True)
class Comment(models.Model):
sno = models.AutoField(primary_key=True, default="1")
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
message = models.TextField()
chellenge_id = models.ForeignKey(
Chellenge, to_field='sno', on_delete=models.CASCADE)
# This one works exact time of current location
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
date_comment = models.DateTimeField(default=now)
why i getting the error django.db.utils.OperationalError: foreign key mismatch - "Comment" referencing "Chellenge" at the time of migrate? how to solve??
Upvotes: 1
Views: 294
Reputation: 605
all the Migration File Delete exclude "init.py" then after run command python manage.py makemigrations
and python manage.py migrate
Upvotes: 2