I am trying to change accepted_answer
ForeignKey to a BooleanField and while migrating getting the error django.db.utils.OperationalError: cannot ALTER TABLE "forum_thread" because it has pending trigger events
. This is the models.py
of before:
class Thread(models.Model):
title = models.CharField(max_length=300)
answer_count = models.PositiveIntegerField(default=0)
added_at = models.DateTimeField(auto_now_add=True)
accepted_answer = models.ForeignKey('forum.Post', null=True, blank=True, related_name='+')
This error seems to happen when trying to update and change schema of the same table in one operation.
For example, after providing new default values when prompted by makemigrations
when removing null=True
from a field, this error seems to appear because Django is trying to change nullability while also updating the column.
Workarounds, depending on situation:
In your specific case, adding a new field then removing the old is probably the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With