The documentation reveals the location of the bug: "For an initial
migration that creates one or more tables (CreateModel operation), Django
checks that all of those tables already exist in the database and fake-
applies the migration if so." But does it check the right database for
those tables? No.
The bug occurs occurs in django.db.migrations.executor.py in the
detect_soft_applied method. It simply compares all models it finds to a
list of tables for the current db `existing_table_names =
self.connection.introspection.table_names(self.connection.cursor())`,
however, if a certain model exists in a different DB as defined in the
app's routers.py, this check will always fail.
Instead, this method should probably consider the return value of the
allow_migrate() method in the app's routers.py before trying to confirm
whether that model should exist in the current db.
--
Ticket URL: <https://code.djangoproject.com/ticket/26117>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
Thanks for the detailed report. Feel free to offer a patch if you are
able.
--
Ticket URL: <https://code.djangoproject.com/ticket/26117#comment:1>
* status: new => assigned
* owner: nobody => scottsexton
Comment:
I'll submit a pull request this weekend.
--
Ticket URL: <https://code.djangoproject.com/ticket/26117#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/6036 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26117#comment:3>
* needs_better_patch: 0 => 1
Comment:
Comments for improvement on the pull request.
--
Ticket URL: <https://code.djangoproject.com/ticket/26117#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"fc584f06859b88474ea0db49bfe142e87428865d" fc584f0]:
{{{
#!CommitTicketReference repository=""
revision="fc584f06859b88474ea0db49bfe142e87428865d"
Fixed #26117 -- Consulted database routers in initial migration detection.
Thanks Simon Charette for help.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26117#comment:5>