繁体   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