[Answered ]-Django db_router does not exclude app models as expected

1👍

Your allow_migrate should return False to indicate that apps other than app_labels are not allowed to migrate in this database:

def allow_migrate(self, db, app_label, model_name=None, **hints):
    if app_label not in self.app_labels:
        return db == "default"
    return False

Returning None as you do means this router doesn’t care about this migration. From the docs for allow_migrate:

Determine if the migration operation is allowed to run on the database with alias db. Return True if the operation should run, False if it shouldn’t run, or None if the router has no opinion.

👤nwself

Leave a comment