Heroku created table but when I'll migrate, he says that doesn't created

前端 未结 2 633
北恋
北恋 2021-01-14 03:34

I made syncdb (Python/Django application) in Heroku and he created table south_migrationhistory,

(venv-project)username@username:~/projectapp$ heroku run py         


        
2条回答
  •  悲哀的现实
    2021-01-14 04:05

    Tested on Django 1.9

    settings.py

    in_heroku = False
    if 'DATABASE_URL' in os.environ:
        in_heroku = True
    
    import dj_database_url
    if in_heroku:
        DATABASES = {'default': dj_database_url.config()}
    else:
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
            }
        }
    

    Then run:

    heroku addons:create heroku-postgresql:hobby-dev
    sudo apt-get intall postgresql libpq-dev
    pip install dj-database-url psycopg2
    pip freeze >requirements.txt
    git add .
    git commit -m 'msg'
    git push heroku master
    heroku run python manage.py migrate
    

    References:

    • There is no more syncdb, just migrate: What should I use instead of syncdb in Django 1.9?
    • https://devcenter.heroku.com/articles/deploying-python
    • https://devcenter.heroku.com/articles/heroku-postgresql

提交回复
热议问题