Opened 9 years ago
Closed 9 years ago
#24795 closed Bug (duplicate)
Migrations fail to apply with postgis 2.0 on remote database
Reported by: | zejn | Owned by: | nobody |
---|---|---|---|
Component: | GIS | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
Problem lies here: https://github.com/django/django/blob/1.8.1/django/contrib/gis/db/backends/postgis/base.py
Beginning with 1.8, the logic to prepare database for test setup has been refactored and the prepare_database() now runs before any migration, not only before tests. This is important, because this now runs even in production.
Since 1.8 supports both Postgis 1.5 and 2.0, the code tries to access the default database, with PostgreSQL this is "postgres" to check the postgis 1.5 template database, specified in POSTGIS_TEMPLATE, actually exists.
I have a production setup using PostgreSQL with Postgis 2.0 on a separate database server. The only accessible database (in pg_hba.conf) for my database user is the database the Django uses. Since code tries to access the database the user does not have access to (postgres), the whole migration process fails.
See https://github.com/django/django/commit/bac7664f274be834a09e037331889959f04a75e7 for the relevant changes.
The bug isn't present in master, because the failing query is only used for Postgis 1.5, which is not supported anymore in master, see https://github.com/zejn/django/commit/26996e2d55719deb0a0b85c642c88658c929106c
I came up with a simple solution, but it's a bit implicit, see https://github.com/zejn/django/commit/acf81f0fe30bff8aa709e37ea10cf63061db4fbc
For the time being I've patched Django.
This is a duplicate of #24791. Looks like this
nodb_connection
was not such a good idea.