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

前端 未结 2 635
北恋
北恋 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
    0 讨论(0)
  • 2021-01-14 04:20

    local_settings.py

    import os
    
    SITE_ROOT = os.path.dirname(__file__)
    
    DEBUG = True
    TEMPLATE_DEBUG = DEBUG
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(SITE_ROOT, 'data.sqlite3'),
        }
    }
    

    In your gitignore, add this:

    project_name/local_settings.py
    *.sqlite3
    
    0 讨论(0)
提交回复
热议问题