I just deployed a flask app to EC2 AWS, and when trying to initialise a sqlite db by using the db.create_all(bind=['layout']) method, an error was shown
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
Here is my code
application.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://{}:{}@{}/{}".format(os.getenv('DB_USER'), os.getenv('DB_PASSWORD'), os.getenv('DB_SERVER'), os.getenv('DB_NAME'))
application.config['SQLALCHEMY_BINDS'] = {
'dashboard': "postgresql://{}:{}@{}/{}".format(os.getenv('DB_USER'), os.getenv('DB_PASSWORD'), os.getenv('DB_SERVER'), os.getenv('DB_NAME')),
'layout': "sqlite:///layout.db"
}
I ran db.create_all(bind=['layout']) in the python shell within the ec2 terminal, and I am not sure why I ran into the error, as it worked perfectly fine on my localhost.
The postgresql database works fine, and can be accessed properly, but the sqlite database, which is the one im trying to initialise with db.create_all(bind=['layout']) leads to the error shown above, and I am not sure why it isnt creating a 'layout.db' file within the current directory.
I am new to deployment, and am not sure if I did anything wrong, do let me know if I configured anything wrongly, thank you!
question from:
https://stackoverflow.com/questions/65903072/sqlite-flask-cant-open-database-file-in-ec2-when-running-db-create-all-comm 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…