0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

`flask db init` にて、 Error: No such command 'db'. エラーとなる

Posted at

flask db init を実行すると、Error: No such command 'db'.

$ flask db init
Usage: flask [OPTIONS] COMMAND [ARGS]...
Try 'flask --help' for help.

Error: No such command 'db'.

help を確認すると、

$ flask --help 
...
Commands:
  routes  Show the routes for the app.
  run     Run a development server.
  shell   Run a shell in the app context.

確かにサブコマンドに db が存在しない。

解決方法は、こちらを参考にした。

コードが足りないと、サブコマンドが生えてこないらしい。。。
以下3つのコードを追記

app.py

from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate # 追記1

db = SQLAlchemy()
migrate = Migrate() # 追記2

def create_app(config_object='app.config'):
    # Flaskアプリケーションの作成
    app = Flask(__name__)

    app.config.from_object(config_object)

    db.init_app(app)
    migrate.init_app(app, db) # 追記3
❯ flask --help
Usage: flask [OPTIONS] COMMAND [ARGS]...

Commands:
  db      Perform database migrations.
  routes  Show the routes for the app.
  run     Run a development server.
  shell   Run a shell in the app context.

生えてきたwww。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?