0

In order to perform a migration, through commands flask db init and flask db migrate, I receive the following error: directory = current_app.extensions['migrate'].directory KeyError: 'migrate'.

I have created a Migrate object within my __init__.py file, however, still receive the error stated above:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

from config import app_config
from flask_login import LoginManager

from flask_migrate import Migrate

# Creating Flask app.
app = Flask(__name__)

# Database variable initialisation.
db = SQLAlchemy()

login_manager = LoginManager()

def create_app(config_name):
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(app_config[config_name])
    app.config.from_pyfile('config.py')
    db.init_app(app)

    # Creating login manager object and initialising it.
    # Login view and message prevent a user to accessing a page they are not authorised to.
    login_manager.init_app(app)
    login_manager.login_message = "Please login to access this page."
    login_manager.login_view = "auth.login"

    migrate = Migrate(app, db)
    from app import models

    return app

Any advice for what I am doing wrong? I have already viewed quite a few pages related to this error and have implemented the possible alterations.

1 Answer 1

1

I found the problem. The above __init__.py class was completely fine.

My config.py file which contained the following code:

SQLALCHEMY_DATABASE_URI = 'mysql+mysqlconnector://{db_user}:{my_password}@localhost/{database}'

... had a format extension to it which was not needed. I have successfully updated my database.

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

Comments

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.