问题描述
尝试在Heroku上运行GeoDjango应用程序,这确实是一项工作.在解决了各种问题之后,我遇到了一个似乎无法摆脱困境的问题.
Trying to run a GeoDjango app on Heroku and it's being a really piece of work. After struggling through a variety of problems, I've come to one I can't seem to hack my way out of.
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 673, in db_parameters
type_string = self.db_type(connection)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/gis/db/models/fields.py", line 105, in db_type
return connection.ops.geo_db_type(self)
AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
我已经正确地使用了dj-database-url
来设置引擎,但是我仍然看到错误
I have properly used dj-database-url
to set the engine, however I'm still seeing the error
我添加了一条print语句来输出我的数据库设置,因为它们正在被py解释
I added a print statement to output my db setups as they're being interpreted by py
在settings.py
中:
if os.getenv('DYNO'):
GDAL_LIBRARY_PATH = os.path.expandvars(os.getenv('GDAL_LIBRARY_PATH'))
GEOS_LIBRARY_PATH = os.path.expandvars(os.getenv('GEOS_LIBRARY_PATH'))
DATABASES['default'] = dj_database_url.parse(os.getenv('DATABASE_URL'),'django.contrib.gis.db.backends.postgis')
print(DATABASES['default'])
这是打印语句,输出heroku服务器解释为我的DATABASES['default']
凭据
Here is the print statement outputting what the heroku server is interpreting as my DATABASES['default']
credentials
{'NAME': 'name', 'USER': 'usr', 'PASSWORD': 'pw', 'HOST': 'herokuec2host.amazonaws.com', 'PORT': 5432, 'CONN_MAX_AGE': 0, 'ENGINE': 'django.contrib.gis.db.backends.postgis'}
任何帮助表示赞赏.我知道有关此问题的各种类似stackoverflow帖子,但是我研究过的所有解决方案都没有解决问题-请再问一遍.
Any help appreciated. I'm aware of the various similar stackoverflow posts regarding this issue, however all of the solutions I've researched have not solved the issue -- so asking again.
推荐答案
Geodjango需要连接"postgis://...",但是heroku将数据库设置更改为"postgres://".因此,如果将DATABASES变量移到settings.py中的底部,则问题已解决.快乐黑客:)
Geodjango need to connect "postgis://..." but heroku change db settings to "postgres://". So, if you move DATABASES variable to bottom in settings.py, problem has been resolved. Happy hacking :)
django_heroku.settings(locals())
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': '*',
'USER': '*',
'PASSWORD': '*',
'HOST': '*',
'PORT': '5432',
},
}
这篇关于在Heroku上使用Django运行PostGIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!