﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24795	Migrations fail to apply with postgis 2.0 on remote database	zejn	nobody	"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."	Bug	closed	GIS	1.8	Normal	duplicate			Unreviewed	1	0	0	0	0	0
