0

I am running the following code in PyCharm and kepp getting the KeyError 'migrate'

import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

basedir = os.path.abspath(os.path.dirname(__file__))
print(basedir)

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(basedir,'data.sqllite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db)

I then run set FLASK_APP=app_database.py and flask db init in command line but I keep getting the directory = current_app.extensions['migrate'].directory KeyError: 'migrate' error.

I am stuck. Can anybody help? Thank you very much!

FBellogi
  • 3
  • 1

1 Answers1

0

Adding migrate = Migrate(app, db) into init.py resolved the issue. (I didn't realize this was necessary for the cli functionality and database initialization, assumed it was related only to database migrations afterwards.)

Running flask db init now works correctly:

Alen John
  • 33
  • 5