2

I have developed a simple flask app locally where I was using SQLite database to perform the login. Now I have deployed it to Heroku and realized that Heroku doesn't support SQLite, that's why now I need to change it to another database.

Here's what I have done with SQLite:

Here's how i have created table:

from sqlalchemy import create_engine
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:///tutorial.db', echo=True)
Base = declarative_base()

# Create USER model

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    username = Column(String)
    password = Column(String)

    def __init__(self, username, password):
        self.username = username
        self.password = password

Base.metadata.create_all(engine)

Here's how i'm using SQlite for login:

from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///tutorial.db', echo=True)

@app.route('/login', methods=['GET', 'POST'])
def lodadata():
    POST_USERNAME = str(request.form['uid'])
    POST_PASSWORD = str(request.form['upass'])

    session = sessionmaker(bind=engine)
    s = session()
    query = s.query(User).filter(User.username.in_([POST_USERNAME]),
                             User.password.in_([POST_PASSWORD]))
    result = query.first()
    if result:
        session['logged_in'] = True
    else:
        flash('Something wrong about Login Detail')

How can I change my database to another DB which supported by Heroku?

Help me, please!

Thanks in advance!

2
  • Make dump of sqlite, import into postgres, change engine in your app. By the way, you can do it locally for testing. this can help you, and this Commented Feb 16, 2018 at 8:19
  • There is 2 point in your question, are you looking for help to migrate your python code or your sql database ? For python part first have a look at docs.sqlalchemy.org/en/latest/core/engines.html#postgresql to use the right engine. For your database it depends if you need to keep your data or not. Commented Feb 16, 2018 at 12:39

0

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.