使用django-constance执行迁移时出错

时间:2017-07-11 15:13:00

标签: django migration

回答之前:是的我已经拥有' constance.backends.database'在我的INSTALLED_APPS和CONSTANCE_CONFIG中,按照默认实现

我刚刚设置了一个拥有django-constance的现有项目 " https://github.com/jazzband/django-constance"

当我进行迁移或迁移时,我得到以下异常:

Traceback (most recent call last):
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "constance_config" does not exist
LINE 1: ...ce_config"."key", "constance_config"."value" FROM "constance...
                                                             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/management/base.py", line 342, in execute
    self.check()
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/management/base.py", line 361, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/urls/resolvers.py", line 313, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/saad/PycharmProjects/Sentimeter/sentimeter-backend/backend/urls.py", line 22, in <module>
    from backend.dashboard import urls as dashboard_urls
  File "/home/saad/PycharmProjects/Sentimeter/sentimeter-backend/backend/dashboard/urls.py", line 3, in <module>
    from backend.dashboard.views.benchmark import BenchmarkView
  File "/home/saad/PycharmProjects/Sentimeter/sentimeter-backend/backend/dashboard/views/benchmark.py", line 9, in <module>
    from sentimeter.services.dates import DateService
  File "/home/saad/PycharmProjects/Sentimeter/sentimeter-backend/sentimeter/services/dates.py", line 8, in <module>
    class DateService:
  File "/home/saad/PycharmProjects/Sentimeter/sentimeter-backend/sentimeter/services/dates.py", line 19, in DateService
    def get_dates(days=config.DEFAULT_NO_OF_DAYS, start_date=None, end_date=None):
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/utils/functional.py", line 235, in inner
    return func(self._wrapped, *args)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/constance/base.py", line 19, in __getattr__
    result = self._backend.get(key)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/constance/backends/database/__init__.py", line 71, in get
    value = self._model._default_manager.get(key=key).value
  File "/home/saad/virtualenvs/sentimeter_backend/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/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/models/query.py", line 379, in get
    num = len(clone)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/models/query.py", line 238, in __len__
    self._fetch_all()
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/models/query.py", line 1087, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/models/query.py", line 54, in __iter__
    results = compiler.execute_sql()
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
    cursor.execute(sql, params)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/saad/virtualenvs/sentimeter_backend/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, 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...

                                                         ^

1 个答案:

答案 0 :(得分:0)

之前我遇到过这种情况。

这是解决此问题的步骤。

我删除所有constance配置(CONSTANCE_CONFIG)以及使用from constance import config

的所有来电

唯一剩下的constance代码就像是

INSTALLED_APPS = (
    ...
    'constance',
    'constance.backends.database',
    ...
) 

...
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
...

之后我能够运行migrate