Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#22576 closed Bug (fixed)

makemigrations requires 'default' database configuration

Reported by: anonymous Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Release blocker Keywords:
Cc: murfi Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to https://docs.djangoproject.com/en/1.7/topics/db/multi-db/, it is OK use an empty dictionary as the 'default' entry in settins.DATABASES in a multi-database setup, but the makemigations management command insists on it being configured.

To reproduce, do "django-admin startproject mmtest", and edit the settings.py:

class DbRouter(object):
   def db_for_read(self, model, **hints):
        return 'nondefault';
   db_for_write = db_for_read

DATABASE_ROUTERS = ('mmtest.settings.DbRouter', )

DATABASES = {
    'default': {},
    'nondefault': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

Stacktrace:

(mmtest)vagrant@localhost:~/mmtest$ ./manage.py makemigrations
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 56, in handle
    loader.build_graph(ignore_unmigrated=True)
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 148, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 48, in applied_migrations
    self.ensure_schema()
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 38, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()):
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 162, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/home/vagrant/.virtualenvs/mmtest/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 18, 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.

Change History (5)

comment:1 Changed 16 months ago by anonymous

  • Component changed from Uncategorized to Migrations
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Type changed from Uncategorized to Bug

comment:2 Changed 16 months ago by timo

  • Triage Stage changed from Unreviewed to Accepted

From django.core.management.commands.makemigrations:

# Load the current graph state. Takes a connection, but it's not used
# (makemigrations doesn't look at the database state).
# Also make sure the graph is built without unmigrated apps shoehorned in.
loader = MigrationLoader(connections[DEFAULT_DB_ALIAS])

The comment doesn't seem accurate given the traceback.

comment:3 Changed 16 months ago by murfi

  • Cc murfi added

comment:4 Changed 16 months ago by Andrew Godwin <andrew@…>

  • Resolution set to fixed
  • Status changed from new to closed

In f9d7e18dc5fa324ed095c6aafd83a34f3086a3de:

Fixed #22576: Ensure makemigrations doesn't touch the database.

comment:5 Changed 16 months ago by Andrew Godwin <andrew@…>

In 2afb6e0526eeffde141d7f2b81dc54df7f45f1ba:

[1.7.x] Fixed #22576: Ensure makemigrations doesn't touch the database.

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