apps: let router control JSON columns post migrations (fixes #29926)

This commit is contained in:
Benjamin Dauvergne 2019-01-22 16:07:10 +01:00
parent 275b7cd4db
commit 72dd3264cc
1 changed files with 4 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import re
from django.apps import AppConfig from django.apps import AppConfig
from django.views import debug from django.views import debug
from django.db import connection from django.db import connection, router
from django.db.models.signals import post_migrate from django.db.models.signals import post_migrate
from . import plugins, compat from . import plugins, compat
@ -13,7 +13,7 @@ class Authentic2Config(AppConfig):
name = 'authentic2' name = 'authentic2'
verbose_name = 'Authentic2' verbose_name = 'Authentic2'
def post_migrate_update_json_column(self, sender, **kwargs): def post_migrate_update_json_column(self, sender, using, **kwargs):
# adapted from https://github.com/kbussell/django-jsonfield-compat/blob/4f6ac4bfaea2224559b174b6d16d846b93d125c6/jsonfield_compat/convert.py # adapted from https://github.com/kbussell/django-jsonfield-compat/blob/4f6ac4bfaea2224559b174b6d16d846b93d125c6/jsonfield_compat/convert.py
# MIT License, kbussel # MIT License, kbussel
if connection.vendor != 'postgresql': if connection.vendor != 'postgresql':
@ -54,6 +54,8 @@ class Authentic2Config(AppConfig):
convert_column_to_json(model, column_name) convert_column_to_json(model, column_name)
for model in list(sender.get_models()): for model in list(sender.get_models()):
if not router.allow_migrate(using, model):
continue
convert_model_json_fields(model) convert_model_json_fields(model)
def ready(self): def ready(self):