21

I've got a GeoDjango instance connected to a PostGIS database backend. When I query a table in this database, I get the error in the title:

AttributeError: 'DatabaseOperations' object has no attribute 'select'

As suggested elsewhere, I checked to make sure that my local_settings.py file specified the correct database engine: 'ENGINE': 'django.contrib.gis.db.backends.postgis'. This is already correct in my settings file.

How do you fix this problem?

1
  • 1
    It sounds as if the engine is not 'django.contrib.gis.db.backends.postgis' despite what you say about local settings, but yo haven’t included enough information to tell why that is the case. Commented Feb 20, 2018 at 22:43

2 Answers 2

37

It sounds as though your Django settings aren't quite right and that your database ENGINE may be 'django.db.backends.postgresql', when it should be 'django.contrib.gis.db.backends.postgis'. To confirm, run:

python manage.py shell

>>> from django.conf import settings
>>> settings.DATABASES
{'default': {'ATOMIC_REQUESTS': False,
  'AUTOCOMMIT': True,
  'CONN_MAX_AGE': 0,
  'ENGINE': 'django.contrib.gis.db.backends.postgis',
  'HOST': '',
  'NAME': 'mydatabase',
  'OPTIONS': {},
  'PASSWORD': '',
  'PORT': '',
  'TEST': {'CHARSET': None, 'COLLATION': None, 'MIRROR': None, 'NAME': None},
  'TIME_ZONE': None,
  'USER': ''}}

The above shows that I have one 'default' database configured and it's using the "postgis" engine (which is what we want).

Watch out for the use of the dj_database_url package in your settings as this may be overriding the database settings from environment variables. Also watch for multiple databases other than "default" in the settings.

Sign up to request clarification or add additional context in comments.

1 Comment

Great explanation ✌🏾
1

Check if you forgot to add,

'django.contrib.gis',

inside your INSTALLED_APPS

1 Comment

You saved my time, thank you ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.