New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrations causes ./manage collectstatic to fail without db #34

ecksun opened this Issue Feb 14, 2017 · 4 comments


None yet
4 participants

ecksun commented Feb 14, 2017

When I try to do collectstatic with PROMETHEUS_EXPORT_MIGRATIONS = True it fails with the following error:

Traceback (most recent call last):
  File "./", line 10, in <module>
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/core/management/", line 353, in execute_from_command_line
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/core/management/", line 327, in execute
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/", line 18, in setup
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/apps/", line 115, in populate
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django_prometheus/", line 24, in ready
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django_prometheus/", line 46, in ExportMigrations
    executor = MigrationExecutor(connections[alias])
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/", line 49, in __init__
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/", line 176, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/", line 65, in applied_migrations
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/", line 233, in cursor
    cursor = self.make_cursor(self._cursor())
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/", line 204, in _cursor
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/", line 199, in ensure_connection
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/", line 199, in ensure_connection
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql/", line 175, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/psycopg2/", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: No route to host
        Is the server running on host "" ( and accepting
        TCP/IP connections on port 5432?

However with PROMETHEUS_EXPORT_MIGRATIONS = True everything works fine.

Running collectstatic should not require a database connection.


This comment has been minimized.

robertobarreda commented Oct 31, 2017

@ecksun PROMETHEUS_EXPORT_MIGRATIONS = False disables django-prometheus ExportMigrations()


This comment has been minimized.

ecksun commented Oct 31, 2017

Yes, I think thats what I tried to say but mistyped in my original comment (though I barely remember this issue).

The issue still stands though, it makes no sense that collectstatic has dependencies on the database.


This comment has been minimized.

arma26 commented Jan 26, 2018

I think it'd be nice if this setting defaulted to False


This comment has been minimized.

nsfyn55 commented Mar 30, 2018

@korfuri as per our email ...

I encountered this same issue both in our Jenkins CI environment and our SCM test kitchen. It would be highly preferable if django_prometheus was agnostic to database activity. This seems to be the only offending functionality

The Error

The Offending Line

executor = MigrationExecutor(connections[alias])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment