我试图在Heroku上的GeoDjango应用程序上运行heroku run python manage.py syncdb
,但是我收到以下错误:
AttributeError:'DatabaseOperations'对象没有属性'geo_db_type'
All of my research已经产生了相同的解决方案:确保使用django.contrib.gis.db.backends.postgis
作为数据库引擎。有趣的是,我已经这样做了(我在django.contrib.gis
也有INSTALLED_APPS
):
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': '...',
'HOST': '...',
'PORT': ...,
'USER': '...',
'PASSWORD': '...'
}
}
INSTALLED_APPS = (
...,
'django.contrib.gis',
)
还有其他我想念的东西吗?非常感谢任何帮助,下面是完整的错误跟踪供参考:
Running `python manage.py syncdb` attached to terminal... up, run.1
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 91, in handle_noargs
sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
File "/app/lib/python2.7/site-packages/django/db/backends/creation.py", line 44, in sql_create_model
col_type = f.db_type(connection=self.connection)
File "/app/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py", line 200, in db_type
return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
更新:我关注了GeoDjango tutorial和Heroku/Django tutorial,并构建了一个适用于我的开发机器的简单应用程序。我使用custom GeoDjango buildpack将它推送到Heroku,并尝试了syncdb,但得到了同样的错误。这是Django / GeoDjango,Heroku或buildpack的问题吗?我的开发环境使用PostgreSQL 9.1和PostGIS 2.0,但是Heroku使用9.0.9和1.5,这可能是问题吗?
OP正在使用GeoDjango buildpack,但是如果有人像我一样使用Geo buildpack和dj_database_url
来到这里,在settings.py
中不要忘记最后一行:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
dj_database_url
directly supports PostGIS。如果您可以将数据库URL更改为以postgis
开头,则可以不使用上面代码中的最后一行。
尝试使用测试数据库集运行测试时出现此错误:
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '_testdb',
}
}
问题是sqlite3 DatabaseOperations
对象没有属性geo_db_type
(就像这篇文章的标题所暗示的那样)。
我的解决方案是将后端更改为sqlite等效的GIS引擎:
'ENGINE': 'django.contrib.gis.db.backends.spatialite'
有关所有可能的后端,请参阅geodjango安装的django文档,并附带安装说明:https://docs.djangoproject.com/en/1.9/ref/contrib/gis/install/#spatial-database
这篇文章很老了,但我只是想分享一下这个问题的答案。我正在使用Dj数据库包,我不知道使用PostGIS时连接URL是不同的。 PostGIS的连接字符串是postgis://USER:PASSWORD@HOST:PORT/NAME
希望这有助于某人。
我遇到了同样的问题,我不得不改变:
'ENGINE': 'django.db.backends.postgresql_psycopg2',
至:
'ENGINE': 'django.contrib.gis.db.backends.postgis',
对我帮助
1)将'django.contrib.gis',
添加到INSTALLED_APPS
2)改变
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
至
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.mysql',
我正在使用堆栈cedar 14上的Python示例应用程序和使用PostGIS的常规Heroko buildpack heroku / python,并且遇到了我的数据库设置被错误的数据库引擎覆盖的相同问题,这导致heroku run python manage.py migrate
失败并出现上述错误。只是在设置中添加引擎不会改变任何东西。经过一些调查,我发现如果我的settings.py正在恢复我的更改,那就是在最后一行调用django_heroku.settings(locals())
。
我通过之后添加一行来重新覆盖引擎来修复它:
django_heroku.settings(locals())
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
我忘了在settings.py中进一步注释掉db设置:
# Update database configuration with $DATABASE_URL.
#db_from_env = dj_database_url.config(conn_max_age=500)
#DATABASES['default'].update(db_from_env)
这些行覆盖了我上面添加的设置
buildpack是这里的罪魁祸首。我没有使用Heroku's buildpack page上列出的GeoDjango buildpack,而是使用了最近更新的one of it's forks。
此外,当我做一个git push heroku master
时,Heroku为应用程序创建了一个开发数据库,当我执行syncdb时,我的DATABASES
设置被忽略,而Heroku尝试使用开发数据库代替......显然是一个问题,因为开发数据库不是t /无法安装PostGIS。因此我在使用git push
(使用correct buildpack)创建dev数据库之后将其销毁,然后运行syncdb并且它可以工作。