Django Migrations declares database unavailable

I am trying to upgrade a Django 1.6.2 application to 1.7.10. I am running PostgreSQL on my Mac using Postgres.app version 9.3.4, which runs PostgreSQL 9.3.4 and PostGIS 2.1.1. The problem I am facing is that when I run the new "makemigrations" command, I get the following error (the entire stacktrace element is at the bottom):

django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend. Try using 'django.db.backends.XXX', where XXX is one of: u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3' Error was: cannot import name BaseSpatialOperations 

Here are the relevant settings:

 # conf/settings/base.py DATABASES = { 'default': { 'ENGINE' : 'django.contrib.gis.db.backends.postgis', 'NAME' : 'geodb', 'USER' : 'geo', 'PASSWORD': 'geopassword', # not really 'HOST' : 'localhost', 'PORT' : '', } } INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.gis', 'apps.admin', # my apps live in an apps subdir. 'apps.home', ) POSTGIS_VERSION = (2,1,1) 

I used the same DATABASE ENGINE installation in my Django 1.6.2 application without any problems. While studying this, some other developers forgot to install psycopg2 in their virtual environment, but I have version 2.6.1 installed in mine. I used version 2.5.2 with Django 1.6.2, but if I go back to psycopg2 for this version, I will still get this error. I read all the psycopg2 release notes between these two versions and did not see anything that could cause this problem.
The GeoDjango tutorial for Django 1.7 also uses this postgis engine mechanism, so it doesn't look deprecated, and in Django 1.7 there is nothing suitable that indicates that this could be a problem.

I also created a test version of the GeoDjango tutorial mentioned above, and if I run the makemigrations command on it, I get the same error.

Finally, I did a web search and don't see articles that discuss this issue with migration / database. Does anyone see what is wrong?

Thanks!

 # Full stacktrace Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute django.setup() File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module> class Permission(models.Model): File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/models/base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, **kwargs)) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/models/base.py", line 297, in add_to_class value.contribute_to_class(cls, name) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__ backend = load_backend(db['ENGINE']) File "/Users/me/venv/dj_17/lib/python2.7/site-packages/django/db/utils.py", line 126, in load_backend raise ImproperlyConfigured(error_msg) django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend. Try using 'django.db.backends.XXX', where XXX is one of: u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3' Error was: cannot import name BaseSpatialOperations 
+6
source share
5 answers

From the ideas, I upgraded Django from 1.7.10 to 1.8.4, and the problem disappeared. I do not know why this is fixed, but it happened.

+2
source

I had problems with similar problems from 1.9.9 to 1.10.1

 django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend. Try using 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3' Error was: cannot import name 'GDALRaster' 

He left by updating the gdal dependency - gdal brew install --upgrade gdal for me on OSX

+3
source

The correct fix is ​​to install the gdal-bin package ( sudo apt-get install gdal-bin ). For Xenial (16.04) it is already available in standard packages. For earlier versions, you may need to complete these two additional steps before doing apt-get install :

 sudo add-apt-repository ppa:ubuntugis/ppa sudo apt-get update 
0
source
 django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql_psycopg' is not an available database backend. Try using 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3' 

Well, I did exactly what was said, changed the engine to:

 "ENGINE":"django.db.backends.postgresql" 

now it works.

(Before that, I tried sudo apt-get install gdal-bin , which did not work -> so if the solution above does not work, you should do it too.)

0
source

Databases in settings.py don't like capital letters (or maybe postresql isn't?).

I fixed this by changing the uppercase letters to lowercase in the "NAME" field of the database.

 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'MyDatabase', <*****WRONG****** 'USER': 'admin', 'PASSWORD': 'pass123', 'HOST': 'localhost', 'PORT': '5432', } } 

Became:

 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydatabase', <*****CORRECT****** 'USER': 'admin', 'PASSWORD': 'pass123', 'HOST': 'localhost', 'PORT': '5432', } } 
0
source

All Articles