I am working through flask following this tutorial. When running the db_migrate.py
script I am getting a file not found error on the open(migrations, "wt")
command.
db_migrate.py
#!flask/bin/python
import imp
from migrate.versioning import api
from app import db
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from confing import basedir
print('Base directory:' + basedir)
print('db path:' + SQLALCHEMY_DATABASE_URI)
print('db repo:' + SQLALCHEMY_MIGRATE_REPO)
version = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (version + 1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
version = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print('New migration saved as ' + migration)
print('Current database version: ' + str(version))
I made a few changes to help debug the script. I even went in to the specified path for the migration script and the error still persists.
This is the output for the script
Base directory: /home/username/src/python/venvs/flask
db path: sqlite:////home/username/src/python/venvs/flask/app.db
db repo: /home/username/src/python/venvs/flask/db_repository
Traceback (most recent call last):
File"./db_migrate.py" line 22, in <module>
open(migration, "wt").write(script)
FileNotFoundError: [Error2] No such file or directory: '/home/username/src/python/venvs/flask/db_repository/versions/001_migration.py'