#26117: Apps with a routers.py file using multiple databases may not use --fake-
initial
-----------------------------+--------------------
Reporter: scottsexton | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
In the case where you have an app that defines a routers.py to associate
certain models with a different database, the initial migration for that
app cannot be faked with --fake-initial. Because some of the models exist
in a different database than the one Django is currently migrating, it
will ignore the fake and try to apply the migration anyway, giving you an
OperationalError that one of the tables already exists.
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/054.565711f6de5526b31fe672a772f22dc4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.