Heroku 上的 Django:在 / 关系 "theblog_category" 处不存在编程错误



我已经阅读了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它是成功的,但是"heroku运行python manage.py migrate"没有成功。消息与以前相同。可能的话,删除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 run bash在heroku上运行迁移,然后再进行迁移。

最新更新