I'm working on a Flask app using SQLAlchemy to interface a sqlite database and Flask-Migrate to manage the migrations.
I generated a first migration script using
flask db init
flask db migrate
I pushed the repo to another server, and I'm trying to create the database using
flask db upgrade
Is this the right procedure?
I'm pretty sure the first time I did this, the sqlite database was created.
I'm trying to do it again on another server, and I get
SqlDatabaseDoesNotExistError: Database "sqlite:////absolute/path/to/sqlite.db" does not exist
I also get the same error if delete and try to recreate the database on the first server.
The directory exists and is writable, but the database file does not exist.
Shouldn't sqlalchemy create the sqlite database if it does not exist?
How am I supposed to create the database? Flask-Migrate documentation is not explicit about this, as this is a sqlite specific issue (other database engine wouldn't create the database automatically, I guess).
I managed to get it to work by first creating the empty DB file first using touch. Maybe that's what I did the other day, I can't remember.
Looks like a permissions issue except I don't get it.
The permissions are:
drwxrwx--- 2 root www-data 4096 Apr 5 18:50 sqlite
and I'm running
flask db upgrade
as root anyway so I don't see why it wouldn't work.
Here's what I did:
touch sqlite/sqlite.db
chown www-data:www-data sqlite/sqlite.db
chmod 600 sqlite/sqlite.db
flask db upgrade
And then it works.
I still have the feeling I'm not doing it the right way.
SQLAlchemy.create_all()could be called by a custom CLI command when you deploy the app the first time