Tips for developing Python apps for Heroku on Windows
This tutorial assumes you have a Heroku account, aren’t super-familiar with Django, and are working on Windows 10.
Start with this tutorial.
You’ll also want to follow these instructions.
I also recommend installing PGAdmin if you want a GUI interface to manage your database.
Key commands
You’ll want to create a separate .env file. I called mine .env.dev. Be sure to add that file to your .gitignore
To start your local instance with your customized .env file run this (make sure you cd into the folder where the app is located):
heroku local web -e .env.dev -f Procfile.windows
Commits
git add . && git commit -m "your message" git push heroku main
Database changes
To keep your local database in sync with Heroku, you’ll need to run the same commands in each environment
Local
python manage.py makemigrations python manage.py migrate
Remote
heroku run python manage.py makemigrations heroku run python manage.py migrate
Reset your sequence
If you copy data from local to remote, your sequences will get messed up. Here’s help on resolving.
select max(id) from "whiskeydiary_whiskey"; select nextval('"whiskeydiary_whiskey_id_seq"'); select setval(pg_get_serial_sequence('"whiskeydiary_whiskey"', 'id'), max(id)) from "whiskeydiary_whiskey"; select max(id) from "whiskeydiary_distillery"; select nextval('"whiskeydiary_distillery_id_seq"'); select setval(pg_get_serial_sequence('"whiskeydiary_distillery"', 'id'), max(id)) from "whiskeydiary_distillery"; select max(id) from "whiskeydiary_whiskeyinstance"; select nextval('"whiskeydiary_whiskeyinstance_id_seq"'); select setval(pg_get_serial_sequence('"whiskeydiary_whiskeyinstance"', 'id'), max(id)) from "whiskeydiary_whiskeyinstance";