I am getting the following error when deploying my app for a test in Heroku:
self = <django.db.backends.utils.CursorWrapper object at 0x7f634cc50a00>
sql = 'CREATE EXTENSION IF NOT EXISTS postgis', params = None
ignored_wrapper_args = (False, {'connection': <django.contrib.gis.db.backends.postgis.base.DatabaseWrapper object at 0x7f635095d2b0>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0x7f634cc50a00>})
def _execute(self, sql, params, *ignored_wrapper_args):
self.db.validate_no_broken_transaction()
with self.db.wrap_database_errors:
if params is None:
# params default might be backend specific.
> return self.cursor.execute(sql)
E django.db.utils.OperationalError: could not open extension control file "/app/.indyno/vendor/postgresql/share/extension/postgis.control": No such file or directory
.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py:82: OperationalError
I have the following code in my app.json file:
{
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-geo-buildpack.git"
},
{
"url": "heroku/python"
}
],
"environments": {
"test": {
"addons": [
"heroku-postgresql:in-dyno"
],
"scripts": {
"test": "pytest"
}
}
}
}
From what I concluded, I see that the error happens when the SQL command 'CREATE EXTENSION IF NOT EXISTS postgis'
is executed.
After searching deeply for a solution, I added the following buildpack: https://github.com/riskmethods/heroku-buildpack-ci-postgis
While this still raised the error; psycopg2.errors.UndefinedFile: could not load library "/app/.indyno/vendor/postgresql/lib/postgis-2.5.so": /app/.indyno/vendor/postgresql/lib/postgis-2.5.so: undefined symbol: AllocSetContextCreateExtended
. It could be solved by using PostgreSQL version 11. I changed my app.json file into this:
{
"environments": {
"test": {
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-geo-buildpack.git"
},
{
"url": "heroku/python"
},
{
"url": "https://github.com/riskmethods/heroku-buildpack-ci-postgis"
}
],
"env": {
"POSTGRESQL_VERSION": "11"
},
"addons": [
"heroku-postgresql:in-dyno"
],
"scripts": {
"test": "pytest"
}
}
}
}