title: Heroku postgres postgis - django releases fail with: relation "spatial_ref_sys" does not exist
body: <p>Heroku changed their PostgreSQL extension schema management on 01 August 2022. (<a href="https://devcenter.heroku.com/changelog-items/2446" rel="noreferrer">https://devcenter.heroku.com/changelog-items/2446</a>)</p>
  <p>Since then every deployment to Heroku of our existing django 4.0 application fails during the release phase, the build succeeds.</p>
  <p>Has anyone experienced the same issue?
  Is there a workaround to push new release to Heroku except reinstalling the postgis extension?</p>
  <p>If I understand the changes right, Heroku added a schema called &quot;heroku_ext&quot; for newly created extensions. As the extension is existing in our case, it should not be affected.</p>
  <blockquote>
  <p>All currently installed extensions will continue to work as intended.</p>
  </blockquote>
  <p>Following the full logs of an release via git push:</p>
  <pre><code>git push staging develop:master
  Gesamt 0 (Delta 0), Wiederverwendet 0 (Delta 0), Pack wiederverwendet 0
  remote: Compressing source files... done.
  remote: Building source:
  remote: 
  remote: -----&gt; Building on the Heroku-20 stack
  remote: -----&gt; Using buildpacks:
  remote:        1. https://github.com/heroku/heroku-geo-buildpack.git
  remote:        2. heroku/python
  remote: -----&gt; Geo Packages (GDAL/GEOS/PROJ) app detected
  remote: -----&gt; Installing GDAL-2.4.0
  remote: -----&gt; Installing GEOS-3.7.2
  remote: -----&gt; Installing PROJ-5.2.0
  remote: -----&gt; Python app detected
  remote: -----&gt; Using Python version specified in runtime.txt
  remote: -----&gt; No change in requirements detected, installing from cache
  remote: -----&gt; Using cached install of python-3.9.13
  remote: -----&gt; Installing pip 22.1.2, setuptools 60.10.0 and wheel 0.37.1
  remote: -----&gt; Installing SQLite3
  remote: -----&gt; Installing requirements with pip
  remote: -----&gt; Skipping Django collectstatic since the env var DISABLE_COLLECTSTATIC is set.
  remote: -----&gt; Discovering process types
  remote:        Procfile declares types -&gt; release, web, worker
  remote: 
  remote: -----&gt; Compressing...
  remote:        Done: 156.1M
  remote: -----&gt; Launching...
  remote:  !     Release command declared: this new release will not be available until the command succeeds.
  remote:        Released v123
  remote:        https://myherokuapp.herokuapp.com/ deployed to Heroku
  remote: 
  remote: This app is using the Heroku-20 stack, however a newer stack is available.
  remote: To upgrade to Heroku-22, see:
  remote: https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack
  remote: 
  remote: Verifying deploy... done.
  remote: Running release command...
  remote: 
  remote: Traceback (most recent call last):
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 87, in _execute
  remote:     return self.cursor.execute(sql)
  remote: psycopg2.errors.UndefinedTable: relation &quot;spatial_ref_sys&quot; does not exist
  remote: 
  remote: 
  remote: The above exception was the direct cause of the following exception:
  remote: 
  remote: Traceback (most recent call last):
  remote:   File &quot;/app/manage.py&quot;, line 22, in &lt;module&gt;
  remote:     main()
  remote:   File &quot;/app/manage.py&quot;, line 18, in main
  remote:     execute_from_command_line(sys.argv)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py&quot;, line 446, in execute_from_command_line
  remote:     utility.execute()
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py&quot;, line 440, in execute
  remote:     self.fetch_command(subcommand).run_from_argv(self.argv)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py&quot;, line 414, in run_from_argv
  remote:     self.execute(*args, **cmd_options)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py&quot;, line 460, in execute
  remote:     output = self.handle(*args, **options)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py&quot;, line 98, in wrapped
  remote:     res = handle_func(*args, **kwargs)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/core/management/commands/migrate.py&quot;, line 106, in handle
  remote:     connection.prepare_database()
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/contrib/gis/db/backends/postgis/base.py&quot;, line 26, in prepare_database
  remote:     cursor.execute(&quot;CREATE EXTENSION IF NOT EXISTS postgis&quot;)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/sentry_sdk/integrations/django/__init__.py&quot;, line 544, in execute
  remote:     return real_execute(self, sql, params)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 67, in execute
  remote:     return self._execute_with_wrappers(
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 80, in _execute_with_wrappers
  remote:     return executor(sql, params, many, context)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 89, in _execute
  remote:     return self.cursor.execute(sql, params)
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py&quot;, line 91, in __exit__
  remote:     raise dj_exc_value.with_traceback(traceback) from exc_value
  remote:   File &quot;/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/utils.py&quot;, line 87, in _execute
  remote:     return self.cursor.execute(sql)
  remote: django.db.utils.ProgrammingError: relation &quot;spatial_ref_sys&quot; does not exist
  remote: 
  remote: Sentry is attempting to send 2 pending error messages
  remote: Waiting up to 2 seconds
  remote: Press Ctrl-C to quit
  remote: Waiting for release.... failed.
  To https://git.heroku.com/myherokuapp
  </code></pre>