New to python here. Working on a basic project using PyCharm Community edition from CRUD-PythonFlask the site. While performing migration steps got errors as below after the command flask db init
:
Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 174, in_run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\elkkanah\PycharmProjects\aquauk\venv\Scripts\flask.exe\__main__.py", line 9, in <m
odule>
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 894, in
main
cli.main(args=args, prog_name=name)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 557, in
main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 717, i
n main
rv = self.invoke(ctx)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 1137,
in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 1137,
in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 956, i
n invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 555, i
n invoke
return callback(*args, **kwargs)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\decorators.py", line
17, in new_func
return f(get_current_context(), *args, **kwargs)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 411, in
decorator
with __ctx.ensure_object(ScriptInfo).load_app().app_context():
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 377, in
load_app
raise_if_not_found=False)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 254, in
locate_app
return find_best_app(script_info, module)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 76, in
find_best_app
app = call_factory(script_info, app_factory)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 114, in
call_factory
return app_factory(script_info)
File "C:\Users\elkkanah\PycharmProjects\aquauk\app\__init__.py", line 19, in create_app
app.config.from_object(app_config[config_name])
KeyError: <flask.cli.ScriptInfo object at 0x0000000003C05B70>
__init__.py
file:
# app/__init__.py
# third-party imports
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_migrate import Migrate
# local imports
from config import app_config
# db variable initialization
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)
login_manager.init_app(app)
login_manager.login_message = "You must be logged in to access this page."
login_manager.login_view = "auth.login"
migrate = Migrate(app, db)
from app import models
# temporary route
@app.route('/')
def hello_world():
return 'Hello, World!'
return app
Need help in sorting the issue. Any help is appreciated.
I have experienced this when using a python file for the FLASK_APP environment variable, rather than using a module (or app in flask terminology), ie:
$ export FLASK_APP=flask_app.py
instead of
$ export FLASK_APP=flask_app:app
I think you may be missing the FLASK_APP entirely though, with flask db init exhibiting that behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With