“no such table” error on Heroku after django syncdb passed

前端 未结 4 688
日久生厌
日久生厌 2021-02-04 13:31

I\'m trying to deploy my Django application to Heroku. The migrations are in my local Git. When I try:

git push heroku master
heroku run python manage.py syncdb
         


        
相关标签:
4条回答
  • 2021-02-04 14:12

    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.

    0 讨论(0)
  • 2021-02-04 14:13

    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.

    0 讨论(0)
  • 2021-02-04 14:23

    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

    0 讨论(0)
  • 2021-02-04 14:23

    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

    0 讨论(0)
提交回复
热议问题