Opened 10 years ago
Closed 10 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 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
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 #24669, which essentially asks for a migration table in each db.
comment:3 by , 10 years ago
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'
comment:4 by , 10 years ago
Cc: | added |
---|
comment:5 by , 10 years ago
Has patch: | set |
---|
comment:6 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:7 by , 10 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Needs improvement as of Markus comment on the patch.
comment:8 by , 10 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Version: | 1.8 → master |
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.
This is a valid use case, there should be a way to support it.
This is somewhat related to #24669.