question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

migrations causes ./manage collectstatic to fail without db

See original GitHub issue

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

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django_prometheus/apps.py", line 24, in ready
    ExportMigrations()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django_prometheus/migrations.py", line 46, in ExportMigrations
    executor = MigrationExecutor(connections[alias])
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", 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/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", 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/base.py", 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/base.py", line 204, in _cursor
    self.ensure_connection()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/utils.py", 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/base.py", line 199, in ensure_connection
    self.connect()
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", 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/base.py", line 175, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/user/proj/app/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", 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 "databaseserver.example.com" (127.1.2.3) 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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:11
  • Comments:5

github_iconTop GitHub Comments

10reactions
arma26commented, Jan 26, 2018

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

4reactions
nsfyn55commented, 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 https://gist.github.com/nsfyn55/6a84438f8ccd3a9e5af688bdc644cdbc

The Offending Line https://github.com/korfuri/django-prometheus/blob/9e77122ac95da695d3de3742cd2e10c11e8c112f/django_prometheus/migrations.py#L46

Read more comments on GitHub >

github_iconTop Results From Across the Web

Collectstatic error while deploying Django app to Heroku
I just updated to Django 1.10 today and had the exact same problem. Your static settings are identical to mine as well. This...
Read more >
Django Makemigrations, Migrate, Collect Static and ...
this command will tell Django to check for changes in our models that we had listed in the INSTALLED_APPS, make the necessary DB...
Read more >
Automatic migrations prevent creation of initial database table ...
What happens is that the django_migrations table gets created. Creation of all other tables are discarded/reverted due to this error. If necessary, I...
Read more >
Problem after upgrading to 2.3 - Google Groups
Database migrations missing - When upgrading to a new NetBox release, ... static files (python3 netbox/manage.py collectstatic --no-input).
Read more >
Unable to use python manage.py migrate : Forums
python manage.py migrate Unknown command: 'migrate' Type ... There is no South database module 'south.db.sqlite3' for your database.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found