使用 Heroku 部署時,如何解決“'django_content_type' 不存在”錯誤? (How can I get past this "'django_content_type' does not exist" error when deploying with Heroku?)


問題描述

使用 Heroku 部署時,如何解決“'django_content_type' 不存在”錯誤? (How can I get past this "'django_content_type' does not exist" error when deploying with Heroku?)

我正在嘗試使用 Heroku 部署我的第一個真實網站。我過去用一個超級簡單的網站成功部署了一次,但這次我似乎卡住了。我可以在本地正常運行該站點。

當我在 Heroku 上單擊免費部署時,它成功地創建應用程序、配置環境和構建應用程序。錯誤來自運行腳本 & scale dynos 部分說'postdeploy exit code was not 0'

我正在使用帶有 cookiecutter‑django 開始我的項目。我還在我的項目中添加了 wagtail 並用它製作了一些相當簡單的頁面。如果您需要查看我的任何其他文件,請告訴我。我對這個不知所措。

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...

                                                             ^



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


Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/contrib/contenttypes/models.py", line 67, in get_for_model
    ct = self.get(app_label=opts.app_label, model=opts.model_name)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/models/manager.py", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/models/query.py", line 381, in get
    num = len(clone)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/models/query.py", line 240, in __len__
    self._fetch_all()
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/models/query.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/models/query.py", line 52, in __iter__
    results = compiler.execute_sql()
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/models/sql/compiler.py", line 848, in execute_sql
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/app/.heroku/python/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 "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...

                                                             ^



During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/management/base.py", line 398, in execute
    self.check()
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/core/checks/model_checks.py", line 28, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailcore/models.py", line 572, in check
    if not issubclass(edit_handler.get_form_class(cls), WagtailAdminPageForm):
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 294, in get_form_class
    formsets=cls.required_formsets(),
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 240, in required_formsets
    formsets.update(handler_class.required_formsets())
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 240, in required_formsets
    formsets.update(handler_class.required_formsets())
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 603, in required_formsets
    'widgets': child_edit_handler_class.widget_overrides(),
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 216, in widget_overrides
    widgets.update(handler_class.widget_overrides())
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 216, in widget_overrides
    widgets.update(handler_class.widget_overrides())
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 516, in widget_overrides
    content_type=cls.target_content_type(), can_choose_root=cls.can_choose_root)}
  File "/app/.heroku/python/lib/python3.5/site‑packages/wagtail/wagtailadmin/edit_handlers.py", line 543, in target_content_type
    cls._target_content_type = [ContentType.objects.get_for_model(target_model)]
  File "/app/.heroku/python/lib/python3.5/site‑packages/django/contrib/contenttypes/models.py", line 80, in get_for_model
    "Error creating new content types. Please make sure contenttypes "
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

參考解法

方法 1:

You may need to run the migration command using:

heroku run python manage.py migrate

方法 2:

Try upgrading to Wagtail 1.4.3 if you're not on it already ‑ the latest release fixes a couple of issues related to bringing up a project database from scratch.

(by Brian Headahmedgasman)

參考文件

  1. How can I get past this "'django_content_type' does not exist" error when deploying with Heroku? (CC BY‑SA 2.5/3.0/4.0)

#wagtail #Python #Django #Heroku






相關問題

Wagtail Cms 是否支持 Google 登錄和用戶登錄添加會話 (Does Wagtail Cms support Google login and user login add session to)

Wagtail Django-form編輯現有對象 (Wagtail Django-form edit existing object)

如何將 Wagtail 'admin' 菜單添加到自定義模板? (How to add Wagtail 'admin' menu to custom templates?)

django.db.utils.OperationalError:外鍵不匹配 - “project_projectpage”引用“auth_user” (django.db.utils.OperationalError: foreign key mismatch - "project_projectpage" referencing "auth_user")

如何使用 Wagtail 鉤子在 Wagtail 中生成自定義鏈接 (How to generate a custom link in Wagtail using Wagtail hooks)

Wagtail:如何設置單元測試以進行簡單的頁面編輯? (Wagtail: How to setup up unittest for simple page edit?)

如何修復錯誤“str”對像沒有屬性“relative_url” (How to fix error 'str' object has no attribute 'relative_url')

如何將帖子從 Wordpress 導入 Wagtail 2(Draftail 編輯器),包括圖像? (How to import posts from Wordpress to Wagtail 2 (Draftail editor) including images?)

如何用外鍵鏈接兩種形式(wagtail 形式和 django 形式)? (How to link two forms (wagtail form and django form) with a foreign key?)

為什麼 RichText 不能在 wagtail 管理員中為帖子工作?這是發生的事情的類型:<h2>嘗試 post.content|richtext</h2> (Why is RichText not working in wagtail admin for posts? This is the type of thing that happens: <h2>Trying post.content|richtext</h2>)

Windows 10 上 wagtail 的客戶端文件夾在哪裡 (Where is the client folder of wagtail on windows 10)

過濾從 Wagtail 核心頁面導入的多個模型的自定義字段 (Filter on custom field across multiple models that import from Wagtail core Page)







留言討論