The problem
I have a project with 50+ migrations in it and recently decided I want to use Constance for a couple of settings.
Everything was OK while developing/adding dynamic settings. I guess it's due to the fact that I setup the Constance config first, did the migration and only then start to use dynamic settings values.
Although when I want to do a test deploy (i.e. when starting up a new Vagrant VM) and run all the migrations from scratch it fails. I am unable to run python manage.py migrate database
, python manage.py migrate
or even python manage.py showmigrations
.
File "/vagrant/my_app/views.py", line 138, in MyViewSet
my_variable = constance_config.MY_VARIABLE
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/utils/functional.py", line 239, in inner
return func(self._wrapped, *args)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/constance/base.py", line 19, in __getattr__
result = self._backend.get(key)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/constance/backends/database/__init__.py", line 74, in get
value = self._model._default_manager.get(key=key).value
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 374, in get
num = len(clone)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 232, in __len__
self._fetch_all()
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 894, in execute_sql
raise original_exception
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 884, in execute_sql
cursor.execute(sql, params)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 80, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/ubuntu/.virtualenvs/venv/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "constance_config" does not exist
LINE 1: ...ce_config"."key", "constance_config"."value" FROM "constance...
So a table that is about to be created is referenced already.
System configuration
- Django version: 1.11.3
- Python version: 3.5.2,