From cd09524f27b83c0ca9dabafa81265e8d8abd252a Mon Sep 17 00:00:00 2001
From: Tim Graham <timograham@gmail.com>
Date: Wed, 12 Oct 2016 21:19:56 -0400
Subject: [PATCH] Fixed #27200 -- Provided makemigration's allow_migrate() with
 model_name.

---
 django/core/management/commands/makemigrations.py | 9 ++++++---
 docs/releases/1.10.3.txt                          | 3 +++
 tests/migrations/test_commands.py                 | 2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index 1fba1a403b..6eb402109f 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -101,9 +101,12 @@ class Command(BaseCommand):
         aliases_to_check = connections if settings.DATABASE_ROUTERS else [DEFAULT_DB_ALIAS]
         for alias in sorted(aliases_to_check):
             connection = connections[alias]
-            if (connection.settings_dict['ENGINE'] != 'django.db.backends.dummy' and
-                    # At least one app must be migrated to the database.
-                    any(router.allow_migrate(connection.alias, label) for label in consistency_check_labels)):
+            if (connection.settings_dict['ENGINE'] != 'django.db.backends.dummy' and any(
+                    # At least one model must be migrated to the database.
+                    router.allow_migrate(connection.alias, app_label, model_name=model._meta.object_name)
+                    for app_label in consistency_check_labels
+                    for model in apps.get_models(app_label)
+            )):
                 loader.check_consistent_history(connection)
 
         # Before anything else, see if there's conflicting apps and drop out
diff --git a/docs/releases/1.10.3.txt b/docs/releases/1.10.3.txt
index 3e40ab6854..13aadb30ee 100644
--- a/docs/releases/1.10.3.txt
+++ b/docs/releases/1.10.3.txt
@@ -14,3 +14,6 @@ Bugfixes
 
 * Fixed a performance regression when running ``migrate`` in projects
   with ``RenameModel`` operations (:ticket:`27279`).
+
+* Added ``model_name`` to the ``allow_migrate()`` calls in ``makemigrations``
+  (:ticket:`27200`).
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index acc4aee83a..6681ceecbc 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -638,7 +638,7 @@ class MakeMigrationsTests(MigrationTestBase):
                 with self.settings(DATABASE_ROUTERS=['migrations.routers.TestRouter']):
                     with mock.patch.object(TestRouter, 'allow_migrate', return_value=False) as allow_migrate:
                         call_command('makemigrations', 'migrations', verbosity=0)
-                allow_migrate.assert_called_with('other', 'migrations')
+                allow_migrate.assert_called_with('other', 'migrations', model_name='UnicodeModel')
                 self.assertEqual(ensure_schema.call_count, 4)
 
     def test_failing_migration(self):