-2👍
The buildpack was the primary culprit here. Instead of using the GeoDjango buildpack listed on Heroku’s buildpack page, I used one of it’s forks that was updated more recently.
Also, when I do a git push heroku master
, Heroku creates a dev database for the app, and when I do a syncdb, my DATABASES
setting is ignored and Heroku tries to use the dev database
instead… obviously an issue, because dev databases don’t/can’t have PostGIS installed. So I destroyed the dev database after it was created with the git push
(with the correct buildpack), then ran syncdb and it works.
100👍
The OP was using the GeoDjango buildpack, but in case anyone gets here using Geo buildpack and dj_database_url
like I was, in settings.py
don’t forget the last line:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
UPDATE
dj_database_url
directly supports PostGIS. You can do without the last line in the code above if you can change your database URL to start with postgis
.
- [Django]-Open the file in universal-newline mode using the CSV Django module
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Django – How to make a variable available to all templates?
41👍
I got this error when trying to run tests with the test db set like so:
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '_testdb',
}
}
The problem is that the sqlite3 DatabaseOperations
object doesn’t have the attribute geo_db_type
(like the title of this post suggests).
My solution was to change the backend to the sqlite equivalent GIS engine:
'ENGINE': 'django.contrib.gis.db.backends.spatialite'
See the Django docs on GeoDjango installation for all the possible backends, with installation instructions: https://docs.djangoproject.com/en/3.0/ref/contrib/gis/install/#spatial-database
- [Django]-Django – Overriding the Model.create() method?
- [Django]-How to convert JSON data into a Python object?
- [Django]-A Better Django Admin ManyToMany Field Widget
28👍
I was having the same problem and I had to change:
'ENGINE': 'django.db.backends.postgresql_psycopg2',
to:
'ENGINE': 'django.contrib.gis.db.backends.postgis',
- [Django]-Django rest framework, use different serializers in the same ModelViewSet
- [Django]-What's the point of Django's collectstatic?
- [Django]-How do Django models work?
18👍
for me helped
1) add 'django.contrib.gis',
to INSTALLED_APPS
2) change from
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
to
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.mysql',
- [Django]-Altering one query parameter in a url (Django)
- [Django]-Are sessions needed for python-social-auth
- [Django]-How to limit the maximum value of a numeric field in a Django model?
13👍
This post is old but I just wanted to share my answer to this problem. I’m using the Dj Database package, and I didn’t know that the connection URL is different when using PostGIS. The connection string for PostGIS is postgis://USER:PASSWORD@HOST:PORT/NAME
Hope this helps someone.
- [Django]-Django CSRF Cookie Not Set
- [Django]-What are the differences between django-tastypie and djangorestframework?
- [Django]-What’s the difference between a project and an app in Django world?
9👍
I’m using the Python sample application on stack cedar 14 and the regular Heroku buildpack Heroku/python with PostGIS and had the same problem that my database settings were overwritten with the wrong DB engine, which caused heroku run python manage.py migrate
to fail with the above error.
Just adding the engine in the settings would not change anything.
After some investigation I found out that it is the call to django_heroku.settings(locals())
in the last line of my settings.py which is reverting my changes.
I fixed it by overwriting the engine again like this by adding a line afterwards:
django_heroku.settings(locals())
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
- [Django]-How to tell if a task has already been queued in django-celery?
- [Django]-How to spread django unit tests over multiple files?
- [Django]-Django stops working with RuntimeError: populate() isn't reentrant
5👍
I changed my default db engine from psycopg2
to postgis
PREVIOUSLY
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
...,
}
}
NOW
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
...,
}
}
- [Django]-What is actually assertEquals in Python?
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
- [Django]-How to upload a file in Django?
1👍
Settings.py > INSTALLED_APPS
INSTALLED_APPS = [
.
.
'django.contrib.gis'
.
]
Settings.py > Databases
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.mysql',
...,
}
}
- [Django]-React Error: Target Container is not a DOM Element
- [Django]-How to send email via Django?
- [Django]-What does this Django regular expression mean? `?P`
-1👍
In may case I was having this issue because I forgot to comment out the db settings further down in settings.py:
# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
These lines were overriding the settings that I had added above. Adding this in case someone else had the same issue.
- [Django]-What is the purpose of adding to INSTALLED_APPS in Django?
- [Django]-Django rest framework, use different serializers in the same ModelViewSet
- [Django]-'pip' is not recognized as an internal or external command