Miles
Miles

Reputation: 3

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

I already read those other Django Heroku questions and I'm still having an error. I'm appreciating your help. I did local migrations already. My website is running on localhost:8000. It's working perfectly and no complaints there. My heroku website is running, but my database isn't there on my heroku server. On Heroku: https://data.heroku.com/datastores/... Health: Available 0 of 10,000 Rows In Compliance 8.1 MB Data Size 0 Table(s)

I suspect that it's a Django migrations problem, but I can't fix it. I tried the following code: heroku run python manage.py migrate. Same error as before. I tried add, commit and push for the heroku server. git add 'theblog/migrations/* git commit -am 'Heroku' git push heroku It was successful, however 'heroku run python manage.py migrate' was not sucessful. Same message as before. Possible, delete the heroku server and I could try again.

On my Heroku website:

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


Upvotes: 0

Views: 476

Answers (2)

Nitesh Singh
Nitesh Singh

Reputation: 395

try this: Delete all the migrations and the db.sqlite3 file and run python manage.py makemigrations again. and then migrate the database again.

Upvotes: 1

Shreehari Vaasistha L
Shreehari Vaasistha L

Reputation: 78

I suggest you run migrations after pushing to heroku. You can try running migrations on heroku by using heroku run bash and then migrate.

Upvotes: 0

Related Questions