django2迁移ProgrammingError

时间:2018-12-18 12:25:32

标签: django django-migrations

自从Django 1.8迁移到2.1以来,我经常会遇到数据库迁移错误。它不会直接在迁移过程中发生,而是在调用manage.py时出现:

django.db.utils.ProgrammingError: relation "obj1_obj2" does not exist
LINE 1: ....

迁移甚至还没有开始,但是它定义了关系或引起错误的任何模型更改。

在本地工作时,我通常回滚代码,然后进行迁移,但是在云提供商上,这是无用的解决方案。我在python 3.6上工作

完整追溯:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 350, in execute
    self.check()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 379, in check
    include_deployment_checks=include_deployment_checks,
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 60, in _run_checks
    issues.extend(super()._run_checks(**kwargs))
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 366, in _run_checks
    return checks.run_checks(**kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 396, in check
     for pattern in self.url_patterns:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
     res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
     return import_module(self.urlconf_name)
  File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/aliz/urls.py", line 8, in <module>
     from camps.urls import api_urlpatterns as camps_api_urlpatterns
  File "/app/camps/urls.py", line 31, in <module>
    path('obecne/', staff_member_required(CurrentEventDetailView.as_view()), {'e_pk': Event.objects.filter(current=True).first().pk}, name='current_camps'),
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 605, in first
    for obj in (self if self.ordered else self.order_by('pk'))[:1]:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 268, in __iter__
    self._fetch_all()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value

0 个答案:

没有答案
相关问题