old_contents: # -*- coding: utf-8 -*-
  
  from django.db.models.signals import pre_save, pre_delete
  from django.dispatch import receiver
  
  
  @receiver(pre_save)
  def save_handler(sender, instance, using, **kwargs):
      # noinspection PyProtectedMember
      if instance._meta.app_label in ("kirppu", "kirppuauth") and using != "default":
          raise ValueError("Saving objects in non-default database should not happen")
  
  
  @receiver(pre_delete)
  def delete_handler(sender, instance, using, **kwargs):
      # noinspection PyProtectedMember
      if instance._meta.app_label in ("kirppu", "kirppuauth") and using != "default":
          raise ValueError("Deleting objects from non-default database should not happen")
  
new_contents: # -*- coding: utf-8 -*-
  
  from django.db.models.signals import pre_migrate, post_migrate
  from django.dispatch import receiver
  
  ENABLE_CHECK = True
  
  
  @receiver(pre_migrate)
  def pre_migrate_handler(*args, **kwargs):
      global ENABLE_CHECK
      ENABLE_CHECK = False
  
  
  @receiver(post_migrate)
  def post_migrate_handler(*args, **kwargs):
      global ENABLE_CHECK
      ENABLE_CHECK = True
  
  
  def save_handler(sender, instance, using, **kwargs):
      # noinspection PyProtectedMember
      if ENABLE_CHECK and instance._meta.app_label in ("kirppu", "kirppuauth") and using != "default":
          raise ValueError("Saving objects in non-default database should not happen")
  
  
  def delete_handler(sender, instance, using, **kwargs):
      # noinspection PyProtectedMember
      if ENABLE_CHECK and instance._meta.app_label in ("kirppu", "kirppuauth") and using != "default":
          raise ValueError("Deleting objects from non-default database should not happen")
  
subject: Allow migrations to be run on extra databases.