GeoDjango:PostgreSQL没有运行迁移,对象没有属性' geo_db_type

时间:2017-09-06 12:50:30

标签: python django postgresql geodjango

Django v1.11.5

我试图安装GeoDjango来玩GoogleMaps。

我为MAC安装了PostgreSQL应用程序并安装了pip install psycopg2。我还用home-brew来安装GDAL。

修改 settings.py 以添加:

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

但是,当我运行python manage.py迁移时,我得到:AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

我使用:CREATE DATABASE djangodb OWNER admin;

创建了用户

完全错误:

  

运行迁移:应用users.0011_location ... Traceback(大多数   最近的呼叫最后一次):文件" manage.py",第22行,in       execute_from_command_line(sys.argv)File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/ init .py&#34 ;,   第364行,在execute_from_command_line中       utility.execute()文件" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/ init .py" ,   第356行,执行中       self.fetch_command(子命令).run_from_argv(self.argv)File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/base.py" ;,   第283行,在run_from_argv中       self.execute(* args,** cmd_options)File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/base.py",   第330行,执行中       output = self.handle(* args,** options)File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/commands/migrate.py& #34 ;,   第204行,处理中       fake_initial = fake_initial,File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py",   第115行,在迁移中       state = self._migrate_all_forwards(state,plan,full_plan,fake = fake,fake_initial = fake_initial)文件   " /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py" ;,   第145行,在_migrate_all_forwards中       state = self.apply_migration(state,migration,fake = fake,fake_initial = fake_initial)文件   " /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/executor.py" ;,   第244行,在apply_migration中       state = migration.apply(state,schema_editor)File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/migration.py",   第129行,申请中       operation.database_forwards(self.app_label,schema_editor,old_state,project_state)文件   " /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/migrations/operations/models.py" ;,   第97行,在database_forwards中       schema_editor.create_model(model)File" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/backends/base/schema.py",   第254行,在create_model中       定义,extra_params = self.column_sql(model,field)文件" /Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/db/backends/base/schema.py&# 34 ;,   第154行,在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&#34 ;,   第662行,在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" ,   第126行,db_type       return connection.ops.geo_db_type(self)AttributeError:' DatabaseOperations'对象没有属性' geo_db_type'

我试过的类似问题: Getting 'DatabaseOperations' object has no attribute 'geo_db_type' error when doing a syncdb

1 个答案:

答案 0 :(得分:6)

您需要更改DATABASES设置以使用postgis后端

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

并将'django.contrib.gis'添加到INSTALLED_APPS