18π
You must not use sqlite3 on Heroku.
sqlite stores the database as a file on disk. But the filesystem in a Heroku dyno is not persistent, and is not shared between dynos. So, when you do heroku run python manage.py migrate
, Heroku spins up a new dyno with a blank database, runs the migrations, then deletes the dyno and the database. The dyno thatβs running your site is unaffected, and never gets migrated.
You must use one of the Heroku database add-ons. There is a free tier for Postgres. You should use the dj-database-url library to set your database settings dynamically from the environment variables which Heroku sets.
Also, for the same reason, you must do manage.py makemigrations
locally, commit the result to git, then push to Heroku.
15π
You can use postgresql:
In settings.py
add(at the end of file):
# ie if Heroku server
if 'DATABASE_URL' in os.environ:
import dj_database_url
DATABASES = {'default': dj_database_url.config()}
In requirements.txt
add:
dj-database-url
psycopg2
Now you can run:
heroku run python manage.py migrate
- Django-templates: Why doesn't {% if "string"|length > 10 %} work at all?
- Django template object type
- (gcloud.app.deploy) Error Response: [7] Access Not Configured. Cloud Build has not been used in project
- Django channels and socket.io-client
- PyCharm: How to switch to regular HTML comments (Ctrl+Slash) in Django
5π
pip install django-heroku
Add import django_heroku
at top of file settings.py
Place django_heroku.settings(locals())
at the very bottom of settings.py
It will automatically configure your db. You can learn more on their website
- Ignoring case with __startswith
- Django DB level default value for a column
- Django + celery β How do I set up a crontab schedule for celery in my django app?
1π
What version of django you are using..?
If you are using django>=1.7 you need to run migrate
After adding models you need to do
python manage.py makemigrations
then python manage.py migrate
If your project already contain migrations you can directly run python manage.py migrate
command.
If you miss any step mentioned above please do that.
- Relation does not exist error in Django
- How to make follower-following system with django model
- Django_rest_swagger β 'staticfiles' is not a registered tag library. Must be one of:
- How do I serve media files in a local Django environment?
- Run django app via nginx+uwsgi in a subpath