簡體   English   中英

Heroku 上的 Django:ProgrammingError at / 關系“theblog_category”不存在

[英]Django on Heroku: ProgrammingError at / relation "theblog_category” does not exist

我已經閱讀了其他 Django Heroku 問題,但我仍然遇到錯誤。 我很感激你的幫助。 我已經進行了本地遷移。 我的網站在 localhost:8000 上運行。 它運行良好,沒有任何抱怨。 我的 heroku 網站正在運行,但我的 heroku 服務器上沒有我的數據庫。 在 Heroku 上: https://data.heroku.com/datastores/... Health: Available 0 of 10,000 Rows In Compliance 8.1 MB Data Size 0 Table(s)

我懷疑這是 Django 遷移問題,但我無法解決。 我嘗試了以下代碼: heroku run python manage.py migrate 和以前一樣的錯誤。 我嘗試添加、提交和推送 heroku 服務器。 git add 'theblog/migrations/* git commit -am 'Heroku' git push heroku It was successful, however 'heroku run python manage.py migrate' was not sucessful. 和以前一樣的消息。 可能,刪除 heroku 服務器,我可以再試一次。

在我的 Heroku 網站上:

relation "theblog_category" does not exist

Traceback
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

The above exception (relation "theblog_category" does not exist
LINE 1: ..._category"."name", "theblog_category"."name" FROM "theblog_c...
                                                             ^
) was the direct cause of the following exception:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 165, in _get_response
    callback, callback_args, callback_kwargs = self.resolve_request(request)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 288, in resolve_request
    resolver_match = resolver.resolve(request.path_info)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 545, in resolve
    for pattern in self.url_patterns:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 589, 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 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 582, 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
    <source code not available>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    <source code not available>
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
    <source code not available>
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    <source code not available>
  File "/app/ablog/urls.py", line 8, in <module>
    path('', include('theblog.urls')),
  File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  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
    <source code not available>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    <source code not available>
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
    <source code not available>
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    <source code not available>
  File "/app/theblog/urls.py", line 3, in <module>
    from .views import HomeView, ArticleDetailView, AddPostView, UpdatePostView, DeletePostView, AddCategoryView, CategoryView, CategoryListView, AddCommentView, AboutView
  File "/app/theblog/views.py", line 4, in <module>
    from .forms import PostForm, EditForm, CommentForm
  File "/app/theblog/forms.py", line 9, in <module>
    for item in choices:
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 287, in __iter__
    self._fetch_all()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 1308, 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 142, in __iter__
    return compiler.results_iter(tuple_expected=True, 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 1108, in results_iter
    results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
    cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 66, 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 75, 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 84, in _execute
    return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /
Exception Value: relation "theblog_category" does not exist
LINE 1: ..._category"."name", "theblog_category"."name" FROM "theblog_c...```


This is my requirements.txt:
asgiref==3.3.1
dj-database-url==0.5.0
Django==3.1.3
django-ckeditor==6.0.0
django-heroku==0.3.1
django-js-asset==1.2.2
gunicorn==20.0.4
Pillow==8.0.1
psycopg2==2.8.6
python-decouple==3.3
pytz==2020.4
sqlparse==0.4.1
whitenoise==5.2.0


試試這個:刪除所有遷移和db.sqlite3文件並再次運行python manage.py makemigrations 然后再次遷移數據庫。

我建議您在推送到 heroku 后運行遷移。 您可以嘗試在 heroku 上運行遷移,方法是使用heroku run bash然后遷移。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM