Python Flask: Unable to Initialize SQLite Database Python Flask: Unable to Initialize SQLite Database flask flask

Python Flask: Unable to Initialize SQLite Database


Pure educated guesswork here. But in the code you've shown you have the following:

@app.cli.command('initdb')def initdb_command():    """Initializes the database."""    init_db()    print('Initialized the database.')

I think that should be

@app.cli.command()def initdb():    ...

Notice that there is no argument to the decorator and that the function was renamed to match the command you are invoking in the command line.

A cursory glance at the Flask and click docs does not show that you can pass a string to the decorator and invoke it as labeled.


I received the same error as I worked through the tutorial. I found that I had opened a new terminal window to work in why the server ran in another. I fixed the issue by running the export command again:

export FLASK_APP=flaskr

Then:

flask initdb


Try this:

python -m flask initdb

Another thing to check, if you're going through the tutorial: is your __init__.py file in the correct location? It should be in the second level flaskr directory, not in the top-level directory.