gpt4 book ai didi

django - 获取 'DatabaseOperations' object has no attribute 'geo_db_type' 做syncdb时报错

转载 作者:行者123 更新时间:2023-11-28 19:33:41 29 4
gpt4 key购买 nike

我试图在 Heroku 上的 GeoDjango 应用程序上运行 heroku run python manage.py syncdb,但出现以下错误:

AttributeError: 'DatabaseOperations' 对象没有属性 'geo_db_type'

All of my research产生了相同的解决方案:确保使用 django.contrib.gis.db.backends.postgis 作为数据库引擎。有趣的是,我已经在这样做了(而且我在 INSTALLED_APPS 中也有 django.contrib.gis):

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 tutorialHeroku/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邮政地理信息系统。如果您可以将数据库 URL 更改为以 postgis 开头,则可以省略上面代码中的最后一行。

关于django - 获取 'DatabaseOperations' object has no attribute 'geo_db_type' 做syncdb时报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12538510/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com