Opened 7 years ago

Closed 7 years ago

#24742 closed Bug (fixed)

Can't runserver on a read-only database due to migrations

Reported by: Luis Del Giudice Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: andrei.avk@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

So i was handed a read only database to develop a Web API.
This is traceback when i runserver

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x10ba2a848>
Traceback (most recent call last):
  File "/Users/delgiudices/Dev/django/django/utils/autoreload.py", line 220, in wrapper
    fn(*args, **kwargs)
  File "/Users/delgiudices/Dev/django/django/core/management/commands/runserver.py", line 111, in inner_run
    self.check_migrations()
  File "/Users/delgiudices/Dev/django/django/core/management/commands/runserver.py", line 158, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/Users/delgiudices/Dev/django/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/delgiudices/Dev/django/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/Users/delgiudices/Dev/django/django/db/migrations/loader.py", line 180, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/Users/delgiudices/Dev/django/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/Users/delgiudices/Dev/django/django/db/migrations/recorder.py", line 53, in ensure_schema
    editor.create_model(self.Migration)
  File "/Users/delgiudices/Dev/django/django/db/backends/base/schema.py", line 284, in create_model
    self.execute(sql, params or None)
  File "/Users/delgiudices/Dev/django/django/db/backends/base/schema.py", line 110, in execute
    cursor.execute(sql, params)
  File "/Users/delgiudices/Dev/django/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/delgiudices/Dev/django/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/delgiudices/Dev/django/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/delgiudices/Dev/django/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "/Users/delgiudices/Dev/django/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/Users/delgiudices/Dev/.envs/python29/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/Users/delgiudices/Dev/.envs/python29/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.OperationalError: (1142, "CREATE command denied to user 'someuser'@'someip' for table 'django_migrations'")

Change History (9)

comment:1 Changed 7 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

This is a valid use case, there should be a way to support it.

This is somewhat related to #24669.

comment:2 Changed 7 years ago by Shai Berger

A workaround could be to add a router that directs all models from the "migrations" app into some sqlite database (in fact, if it works, it could be packed up nicely as a solution).

However, indeed, such a solution flies in the face of #24699, which essentially asks for a migration table in each db.

Version 0, edited 7 years ago by Shai Berger (next)

comment:3 Changed 7 years ago by andrei kulakov

Adding a router that redirects migrations to a different db is exactly what I did for a recent project, - it works just fine.

[edit] After looking it up, I did the reverse: I defined default writable db and set up routers for all read-only dbs:

class AppRouter(object):
    app_name = None
    def db_for_read(self, model, **hints):
        if model._meta.app_label == self.app_name:
            return self.app_name
        return None

class ReadonlyRouter(AppRouter):
    app_name = 'my_ro_app'
Last edited 7 years ago by andrei kulakov (previous) (diff)

comment:4 Changed 7 years ago by andrei kulakov

Cc: andrei.avk@… added

comment:5 Changed 7 years ago by Claude Paroz

Has patch: set

comment:6 Changed 7 years ago by Aymeric Augustin

Triage Stage: AcceptedReady for checkin

comment:7 Changed 7 years ago by Claude Paroz

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Needs improvement as of Markus comment on the patch.

comment:8 Changed 7 years ago by Markus Holtermann

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin
Version: 1.8master

Patch looks good to me. FTR, I don't consider this something we should backport, unless it's an error that didn't happen on 1.7.

PR: https://github.com/django/django/pull/4636

comment:9 Changed 7 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In f61c4f4:

Fixed #24742 -- Made runserver.check_migrations ignore read-only databases

Thanks Luis Del Giudice for the report, and Aymeric Augustin and Markus
Holtermann for the reviews.

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