Forums

Web app ignores my sqlite database (flask)

Hello! I use Flask with SQLIte database (sqlalchemy package).

I have uploaded all files with my Flask application to pythonanywhere. When I execute some code with engine.execute() in Python files (by bash) it works well.

But when I run my Web App on host -- feels like the app ignores SQLite execution "parts" and continue the way through all back-end.

P.S.: interface on website looks great and all parts except SQL executions works great as well. Also, all works well on my local machine.

Where is the problem? Please, help.

how do you pass in the sqlite database? is it a relative path or an absolute path?

In database.py I have this:

engine = create_engine("sqlite:///test.db", convert_unicode=True)

db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))

Base = declarative_base()

Base.query = db_session.query_property()


    def init_db():

    import dbsql.models
    Base.metadata.create_all(bind=engine)

In app.py I import init_db()

See http://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/ about using relative path names when referring to files.

Thank you for the help!

I added absolute paths to all links in my app and everything works great now.

engine = create_engine("sqlite:////home/username/application/test.db", convert_unicode=True)

Excellent, glad you got it working!

Thank you for this post. I had the same problem and this solution helped.