#27054: makemigrations tries to create django_migrations in external database
---------------------------------+------------------------------------
Reporter: Jim Nicholls | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Comment (by MiddleFork):
#27110 breaks this fix in the case where a database is present in
DATABASES but absent from DATABASE_ROUTERS.
In spite of #27110 testing for DATABASE_ROUTERS, makemigrations still
using the connections in django.db.utils.ConnectionHandler (ie as
populated from settings.DATABASES) rather than the routers in
DATABASE_ROUTERS for the set of databases for which it attempts to prepare
to migrate.
This simplified example should result in makemigrations failing:
{{{
DATABASES = {
'default': { ... }
'read_only': { ... }
}
Class MyDefaultRouter():
class Meta:
DATABASE_ROUTERS = ['MyDefaultRouter',]
}}}
As long as we explicitly specify our database by employing the
.objects.using() syntax, the database need not be present in
DATABASE_ROUTERS
{{{
class MyReadOnlyModel(models.Model):
class Meta
queryset = MyReadOnlyModel.objects.using('read_only').all()
}}}
so at line 109 of makemigrations the call to
loader.check_consistent_history(connection) on our read-only database, and
will again raise the applied_migrations / ensure_schema traceback
{{{
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/core/management/__init__.py", line 367, in
execute_from_command_line
utility.execute()
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/core/management/commands/makemigrations.py", line 109, in
handle
loader.check_consistent_history(connection)
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/db/migrations/loader.py", line 276, in
check_consistent_history
applied = recorder.applied_migrations()
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/bigdata/django/bdp/bdpproj/venv/lib/python2.7/site-
packages/django/db/migrations/recorder.py", line 59, in ensure_schema
raise MigrationSchemaMissing("Unable to create the django_migrations
table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create
the django_migrations table ((1142, "CREATE command denied to user
'readonly_user'@'192.168.1.1' for table 'django_migrations'"))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27054#comment:15>
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/078.fa6ee3c97cfe48c4b20e1a8847a8e023%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.