0

I created two databases using the following code with python+flask+sqlalchemy

from flask import Flask 
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///C:\\Users\\dmac'
app.config['SQLALCHEMY_BINDS'] = {
   'user': 'sqlite:///C:\\Users\\dmac\\user.db',
   'stock': 'sqlite:///C:\\Users\\dmac\\price.db'
}
db = SQLAlchemy(app)
migrate = Migrate(app, db, render_as_batch = True)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
   manager.run()

I run the following script:

python app.py db init--multi 
python app.py migrate

I get the following error: sqlalchemy.exc.OperationalError:(sqlite3.OperationalError) unable to open database file (Background on this error at: http://sqlalche.me/e/e3q8)

I have looked and tried different solutions posted, but I still get the same errors. Any helps would be appreciative. Thanks

1
  • Here are the versions: python-3.6, flask-1.0.2, flask-migrate-2.5.3, flask-script-2.0.6 Commented May 27, 2021 at 20:46

1 Answer 1

1

I think the problem is that you're pointing SQLALCHEMY_DATABASE_URI to a folder instead of a database. So SQLAlchemy tries to open the dmac folder as if it were a database which it isn't and fails.

https://flask-sqlalchemy.palletsprojects.com/en/2.x/binds/

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

1 Comment

I see. Thank you. I will take a look.

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.