0

I'm getting the next error while trying to run my Flask app:

sqlalchemy.exc.OperationalError
OperationalError: (_mysql_exceptions.OperationalError) (1049, "Unknown database '/home/gerardo/Documentos/python_web_dev/flask-intro/app2.db'")

so it seems like there is no database.. but I ran the next scripts using sqlalchemy_utils and everything was ok:

engine = create_engine("mysql://root:@localhost/home/gerardo/Documentos/python_web_dev/flask-intro/app2.db")

create_database(engine.url)

but still I get the error..

1 Answer 1

1

You have confused MySQL, a database server, with SQLite, a database in a file. You created a SQLite file, but are trying to tell MySQL to connect to it, which makes no sense.

Use the sqlite dialect in the connection string.

You can avoid typing the whole path (and tying the app to that path) by pointing to the file relative to the app's location.

import os
db_path = os.path.realpath(os.path.join(os.path.dirname(__file__), 'app2.db'))
engine = create_engine('sqlite://{}'.format(db_path))

Consider using Flask-SQLAlchemy rather than trying to manage the database yourself.

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

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.