Reputation: 41
I have a Django app deployed on Heroku. I am trying to switch the database from mySQL to Postgres using the Heroku Postgres addon
I erased all migrations and ran manage.py makemigrations to get a clean migration log. Then I commit and push.
If I run manage.py migrate on my local machine, this is what I get: Migrations for 'manager':
manager/migrations/0001_initial.py
- Create model AbiMapping
- Create model MissingContracts
- Create model TempEmailAccounts
- Create model UnsupportedMetaContracts
- Create model Users
- Create model Passwords
- Create model ContractMapping
- Create model Tokens
I added this command to Procfile so migrate runs when I push to Heroku:
release: python3 manage.py migrate
When pushing to Heroku, the migrate call works but it doesn't migrate the models I have in the app:
remote: Verifying deploy... done.
remote: Running release command...
remote:
remote: Operations to perform:
remote: Apply all migrations: admin, auth, contenttypes, manager, sessions
remote: Running migrations:
remote: No migrations to apply.
This is how I setup the database is settings.py:
.env sets environment variables on local machine. On heroku database environment variables are loaded from environment as there is not .env
dotenv_file = os.path.join(BASE_DIR, ".env")
if os.path.isfile(dotenv_file):
dotenv.load_dotenv(dotenv_file)
Setup database:
DATABASES = {}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
django_on_heroku.settings(locals())
it seems like the database does exist in heroku:
$ heroku config
=== frame-zero Config Vars
DATABASE_URL: postgres://<details of my database address and credentials>
Thank you
Upvotes: 0
Views: 256
Reputation: 1
Already solved here. the trick is to run the bash on Heroku Dyno first. first run Heroku run bash
then inside the bash window run Python manage.py makemigrations
and after that Python manage.py migrate
.
Upvotes: 0