Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26930 closed Bug (fixed)

makemigrations tries to access default databases even when set to empty

Reported by: lizlemon Owned by: nobody
Component: Migrations Version: 1.10
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

makemigrations always tries to access the default database, so it raises an error when settings.DATABASES 'default' key is set to empty dict. This was fixed previously in #22576, but there has been a regression.

The issue appears to be in django/core/management/commands/makemigrations.py

        for db in connections:
            loader.check_consistent_history(connections[db])

in settings.py:

DATABASES = {
    'default': {},
    'leftside': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db-left.sqlite3'),
    },
    'rightside': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db-right.sqlite3'),
    }
}

Then create a model in an application and define a router for it, and then run manage.py makemigrations

With 1.8 and other releases this will create the migrations, but current version raises an error:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/core/management/base.py", line 356, in execute
    output = self.handle(*args, **options)
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/core/management/commands/makemigrations.py", line 98, in handle
    loader.check_consistent_history(connections[db])
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/db/migrations/loader.py", line 276, in check_consistent_history
    applied = recorder.applied_migrations()
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/db/backends/base/base.py", line 238, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/home/lemon/code/envs/dj34/lib/python3.4/site-packages/django/db/backends/dummy/base.py", line 21, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Attachments (2)

26930-test.diff (1.5 KB ) - added by Claude Paroz 8 years ago.
Failing test case
26930-patch.diff (1.1 KB ) - added by lizlemon 8 years ago.
fixes the issue

Download all attachments as: .zip

Change History (9)

comment:1 by Tim Graham, 8 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Version: master1.10

Regression in 1.10 due to 02ae5fd31a56ffb42feadb49c1f3870ba0a24869.

by Claude Paroz, 8 years ago

Attachment: 26930-test.diff added

Failing test case

by lizlemon, 8 years ago

Attachment: 26930-patch.diff added

fixes the issue

comment:3 by lizlemon, 8 years ago

Has patch: set

comment:5 by Tim Graham, 8 years ago

Patch needs improvement: set

As noted on the PR, I don't using is_usable() is the best way to identify the dummy database backend.

comment:6 by Tim Graham, 8 years ago

Patch needs improvement: unset

New PR

comment:7 by GitHub <noreply@…>, 8 years ago

Resolution: fixed
Status: newclosed

In aad46c3:

Fixed #26930 -- Prevented makemigrations from accessing an empty database.

Thanks Liz Lemon for the report and investigation and
Claude Paroz for the test.

comment:8 by Tim Graham <timograham@…>, 8 years ago

In ddcf7dba:

[1.10.x] Fixed #26930 -- Prevented makemigrations from accessing an empty database.

Thanks Liz Lemon for the report and investigation and
Claude Paroz for the test.

Backport of aad46c3e370e105f9117a337924090d05f1b001d from master

Note: See TracTickets for help on using tickets.
Back to Top