django.db.utils.OperationalError: cannot ALTER TABLE "news_article" because it has pending trigger events
So, I have the following problem:
I have a Django class, Article, which contains several Char- and TextFields. They were set to blank=True
AND null=True
which is... unfortunate. Oh well, no I need to fix that. So after I deleted null=True
and set default=''
, I wrote the following thing into my migration:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import languagefields.utils
from languagefields.utils import LANGUAGES
from django.utils.translation import activate
from news.models import Article
def null_migrations(apps, schema_editor):
activate('en')
fields = ['short_title', 'description']
for p in Article.objects.all():
for l in LANGUAGES:
for f in fields:
if p.get_language(l, f) is None:
p.set_localized(l, f, '')
p.save()
class Migration(migrations.Migration):
dependencies = [
('news', '0001_initial'),
]
operations = [
migrations.RunPython(null_migrations),
migrations.AlterField(....
The fields are custom fields, based on the default Char-/TextFields, which enable translation. So there is a bunch of them. For every field you create there will be 5, a description in english, german and so on... So yeah, the little function works fine, I ran it on the server and cleaned the db entries manually, but that doesn't stop the exception above. So I thought I'd put it in the migration to clean out on the go. But still the exception. What am I doing wrong?
Thank you in advance :)
EDIT
Split up the migrations in two:
0002_null_cleaning.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import languagefields.utils
from languagefields.utils import LANGUAGES
from django.utils.translation import activate
from news.models import Article
def null_migrations(apps, schema_editor):
activate('en')
fields = ['short_title', 'description']
for p in Article.objects.all():
for l in LANGUAGES:
for f in fields:
if p.get_language(l, f) is None:
p.set_localized(l, f, '')
p.save()
class Migration(migrations.Migration):
dependencies = [
('news', '0001_initial'),
]
operations = [
migrations.RunPython(null_migrations),
]
0003_data_migration
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import languagefields.utils
class Migration(migrations.Migration):
dependencies = [
('news', '0002_null_cleaning'),
]
operations = [
migrations.AlterField(...
Still the same error, happening for 0003