1

enter image description here

I'm trying to extend the flask-base project https://github.com/hack4impact/flask-base/tree/master/app .

I have used flask-migrate to create migrations for my local sqlite db.

I now need to migrate from the local sqlite db to heroku's postgres. Following https://www.quora.com/What-is-the-best-way-to-copy-my-SQLite-database-to-PostgreSQL-so-I-can-deploy-it-to-Heroku , I'm trying I set up a local postgres db called 'test' (screenshot)

I set:

os.environ["TEST_DATABASE_URL"] = "postgresql+psycopg2://127.0.0.1:5432/test"   # REMOVE THIS !!!!!!!!!!

There is a test config in the config.py containing:

class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
        'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')

    print('TestingConfig - psgres?')
    print(SQLALCHEMY_DATABASE_URI)

    WTF_CSRF_ENABLED = False

However when I perform the upgrade with flask-migrate:

$ python manage.py db upgrade


TestingConfig - psgres?
postgresql+psycopg2://127.0.0.1:5432/test

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 78401e355127, empty message

A new sqlite db is created. Obviously I'm not connecting to the postgres test db. How can I get this working?

1

2 Answers 2

1

in this case the environmental variables were not being recognized initially, but when I rebooted later they did start working.

os.environ["TEST_DATABASE_URL"] = "postgresql://[email protected]:5432/postgres" 

worked.

Sign up to request clarification or add additional context in comments.

Comments

0

I was also doing the migration and I've recorded it in short post:

Migrating form SqlLite to Postgresql in Flask

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.