Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enable GeoDjango on an already-existing postgres database on Webfaction?

I'm running Django 1.8.4 on a Webfaction shared host, and I need to enable GeoDjango. These are the steps I took:

  1. Converted my project to use GeoDjango as per the documentation.
  2. In the Webfaction UI, added the PostGIS extension to my database.
  3. Ran ./manage.py migrate. Here's the error:

    django.db.utils.OperationalError: could not open extension control file "/usr/pgsql-9.1/share/extension/postgis.control": No such file or `directory
    
like image 437
seddonym Avatar asked Aug 26 '15 16:08

seddonym


1 Answers

There is a simple, horrible way to get this working. Specify the following setting as the same name as your webfaction database:

# settings.py

...
POSTGIS_TEMPLATE = 'my_database_name'

Now ./manage.py migrate should work as normal.

Explanation

The reason for this error is because Django thinks that PostGIS is not installed on the database, and is attempting to install it as an extension, PostGIS 2 style.

The test it performs is to see if the PostGIS database template is present. If it isn't, it attempts to install it in a way that is incompatible with PostGIS < 2 (which is what is installed on Webfaction).

By changing this setting, Django checks to see if the normal database is present (instead of the PostGIS template) and then concludes that everything is set up correctly - which it is. The wrong test, but the right result.

If you're curious as to what exactly is going on, have a look at django.contrib.gis.db.backends.postgis.base.DatabaseWrapper.

like image 176
seddonym Avatar answered Oct 21 '22 23:10

seddonym