Valachio
Valachio

Reputation: 1135

Django on Heroku - ProgrammingError at / relation "..." does not exist

I'm getting this error. I know you usually get this error because the databases wasn't properly migrated.

When I run heroku local web, the website works fine when I go to localhost:5000.

However after I deploy the app to heroku with git push heroku master, the error comes up.

In other words, it works in my local environment. But it does not work after deploying to heroku.

I have Heroku-Postgres installed as an add-on in heroku.

What could be causing this?

Upvotes: 4

Views: 4889

Answers (3)

Julkar9
Julkar9

Reputation: 2110

The following steps did it for me

  1. Make all the necessary migrations (python manage.py makemigrations) and migrate (python manage.py migrate) locally,
  2. push to heroku master
  3. and finally running heroku run python manage.py migrate

Solved the issue

Upvotes: 1

femeloper
femeloper

Reputation: 96

I experienced the same error after making a change to a model and then deploying this change to heroku.

The only way I managed to fix this problem was to do the following:

  • Reset the database in heroku
  • Delete the migrations files from the migrations folder for the broken app locally (but keep the directory and the __init__.py file)
  • Run python manage.py makemigrations and python manage.py migrate. This will repopulate the migrations folder with clean migration files.
  • Push changes to master (ensure that you do not have migrations directories in .gitignore files.
  • Deploy changes to heroku
  • Run the heroku shell heroku run bash
  • Run python manage.py migrate

I was able to do this because my tables did not have much data in, but I would try to avoid resetting the database if I had more data in my tables.

Upvotes: 0

LSM
LSM

Reputation: 330

excute migrations and makemigrations in bash heroku. open the terminal in the local project folder and give the following commands:

heroku run bash
~$  ./manage.py makemigrations
~$  ./manage.py migrate
~$  exit

Upvotes: 5

Related Questions