Opened 8 years ago

Closed 3 years ago

#27141 closed Cleanup/optimization (fixed)

makemigrations fails with PermissionDenied on django_migrations

Reported by: Sjoerd Job Postmus Owned by: nobody
Component: Migrations Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On a project I'm currently working on, I have read-only access to 1 table on a database.

Similar to #27054, except that the table django_migrations does exist, I just don't have read-access to it.

Error message:

django.db.utils.ProgrammingError: permission denied for relation django_migrations.

The error occurs in recorder.py:MigrationRecorder.applied_migrations, specifically the line

return set(tuple(x) for x in self.migration_qs.values_list("app", "name"))

Change History (9)

comment:1 by Sjoerd Job Postmus, 8 years ago

Pull request at https://github.com/django/django/pull/7172

Let me know if I missed anything.

comment:2 by Claude Paroz, 8 years ago

Component: UncategorizedMigrations
Has patch: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:3 by Sjoerd Job Postmus, 8 years ago

Responding to Tim Graham his remark on the pull request:

Sure, you could let us know how inspectdb currently works with this situation. I guess it might hit that exception block. I guess if that's better than silently skipping such tables then that solution may not be ideal, or at least we'd need a new parameter to introspection.table_names() to skip unowned tables.

Yes, I'm indeed hitting the exception handler there. Based on results from Django==1.9.7, it comes from get_table_description which has a SELECT * FROM %s LIMIT 1.

So I think what would make the most sense would be to add a try/except DatabaseError around the part where the applied migrations are obtained, and then (re-)raise a MigrationSchemaMissing instead. The error message is after all correct: "\nNot checking migrations as it is not possible to access/create the django_migrations table.".

comment:4 by Tim Graham, 8 years ago

Has patch: unset

Feel free to send a pull request to my branch or give my PR a review so we can merge it and continue this ticket in a new PR.

comment:5 by Tim Graham, 8 years ago

In ticket:27142#comment:3 I asked whether or not we should even keep this check in makemigrations. It's getting tedious to deal with all the edge cases, with questionable benefit in my view.

comment:6 by ldng, 8 years ago

A similar usesase but maybe needing a different solution (or even a different ticket) is that of a read only database connection.

Say you have :

DATABASES = {
    'default': ...,
    'another_db_rw': ...,
    'yet_another_db_r': ...,
}

makemigrations will try to "make" migrations for all 3 connections. Maybe a solution for that would be a '--database' option like migrate command ?

Version 0, edited 8 years ago by ldng (next)

comment:7 by Tim Graham, 8 years ago

You should set up database routers so that allow_migrate() returns False for read-only connections.

comment:9 by Jacob Walls, 3 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top