Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoDjango: PostgreSQL not running migrations, object has no attribute 'geo_db_type

Django v1.11.5

I'm trying to install GeoDjango to play around with GoogleMaps.

I installed PostgreSQL app for MAC and installed pip install psycopg2. I also used home-brew to install GDAL.

Edited settings.py to add:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'djangodb',
        'USER': 'admin',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

However, when I run python manage.py migrate I get: AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

I created the user using:CREATE DATABASE djangodb OWNER admin;

Full Error:

Running migrations: Applying users.0011_location...Traceback (most recent call last): File "manage.py", line 22, in execute_from_command_line(sys.argv) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/init.py", line 364, in execute_from_command_line utility.execute() File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/init.py", line 356, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle fake_initial=fake_initial, File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 115, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 97, in database_forwards schema_editor.create_model(model) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 254, in create_model definition, extra_params = self.column_sql(model, field) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 144, in column_sql db_params = field.db_parameters(connection=self.connection) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/models/fields/init.py", line 662, in db_parameters type_string = self.db_type(connection) File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/db/models/fields.py", line 126, in db_type return connection.ops.geo_db_type(self) AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

Similar questions I tried: Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb

like image 537
Roma Avatar asked Sep 06 '17 12:09

Roma


1 Answers

You need to change your DATABASES setting to use the postgis backend,

'ENGINE': 'django.contrib.gis.db.backends.postgis',

and add 'django.contrib.gis', to INSTALLED_APPS.

like image 127
Alasdair Avatar answered Oct 07 '22 10:10

Alasdair