0

We are trying to run a flask db migrate and flask db upgrade which throws the following error:

Usage: flask db upgrade [OPTIONS] [REVISION]

Error: The file/path provided (C) does not appear to exist.  Please verify the path 
           is correct.  If app is not on PYTHONPATH, ensure the extension is .py

We have added the app's directory to the PYTHONPATH environment variable but still get the error. Any help would be appreciated.

Below is our __init__.py code. Are we missing something?

import logging
from flask import Flask
from flask_appbuilder import SQLA, AppBuilder

"""
 Logging configuration
"""

logging.basicConfig(format='%(asctime)s:%(levelname)s:%(name)s:%(message)s')
logging.getLogger().setLevel(logging.DEBUG)

app = Flask(__name__)
app.config.from_object('config')
db = SQLA(app)
appbuilder = AppBuilder(app, db.session)
migrate.init_app(app, db)


"""
from sqlalchemy.engine import Engine
from sqlalchemy import event

#Only include this for SQLLite constraints
@event.listens_for(Engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
    # Will force sqllite contraint foreign keys
    cursor = dbapi_connection.cursor()
    cursor.execute("PRAGMA foreign_keys=ON")
    cursor.close()
"""    

from app import views
2
  • Are you in the flask app directory when you run the command? Have you configured your app to use migrate as shown here - flask-migrate.readthedocs.io/en/latest. app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db' db = SQLAlchemy(app) migrate = Migrate(app, db) Commented Aug 29, 2018 at 9:14
  • We are in the correct directory however we may not have configured the app correctly. The code you refer to needs to be added to __init__.py correct? Commented Aug 29, 2018 at 9:35

1 Answer 1

4

I think if you are using migrate like you are

migrate.init_app(app, db)  

that you first have to import it and then declare it:

from flask_migrate import Migrate
migrate = Migrate()
migrate.init_app(app, db)

or alternatively I think you could do:

from flask_migrate import Migrate
migrate = Migrate(app, db) 
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.