无法在 Heroku 上安装 Postgis CI

Cannot install Postgis on Heroku CI

在 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

我的 app.json 文件中有以下代码:

{
  "buildpacks": [
    {
      "url": "https://github.com/heroku/heroku-geo-buildpack.git"
    },
    {
      "url": "heroku/python"
    }
  ],
  "environments": {
    "test": {
      "addons": [
        "heroku-postgresql:in-dyno"
      ],
      "scripts": {
        "test": "pytest"
      }
    }
  }
}

根据我的结论,我发现错误发生在执行 SQL 命令 'CREATE EXTENSION IF NOT EXISTS postgis' 时。

在深入搜索解决方案后,我添加了以下构建包: https://github.com/riskmethods/heroku-buildpack-ci-postgis

虽然这仍然引发错误; 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。它可以通过使用 PostgreSQL 版本 11 来解决。我将我的 app.json 文件更改为:

{

  "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"
      }
    }
  }
}