官网中的示例代码
flask init-db
flask db init
给代替了运行
flask db init
报错
Usage: flask db init [OPTIONS]
Error: Failed to find Flask application or factory in module "app". Use "FLASK_APP=app:name to specify one.
set FLASK_APP=manage.py
flask db init
运行
flask db migrate
报错
d:\programfiles\anaconda3\envs\netdevops\lib\site-packages\flask_sqlalchemy\__init__.py:774: UserWarning: Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. Defaulting SQLALCHEMY_DATABASE_URI t
o "sqlite:///:memory:".
'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. '
d:\programfiles\anaconda3\envs\netdevops\lib\site-packages\flask_sqlalchemy\__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by defaul
t in the future. Set it to True or False to suppress this warning.
问题解决
SQLALCHEMY_DATABASE_URI 和SQLALCHEMY_TRACK_MODIFICATIONS
这两项都是必须的,不可以省略 # 1. 导入配置
app.config.from_object(Config)
# 2. 配置数据库
db = SQLALCHEMY(app)
migrate = Migrate(app)
mysql 1366 VARIABLE_VALUE incorrect
d:\programfiles\anaconda3\envs\netdevops\lib\site-packages\sqlalchemy\engine\default.py:552:
Warning: (1366, "Incorrect string value: '\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...'
for column 'VARIABLE_VALUE' at ro
w 484")
# 报错写法
SQLALCHEMY_DATABASE_URI = "mysql://root:root@127.0.0.1:3306/mydb"
# 正确写法
SQLALCHEMY_DATABASE_URI = "mysq+mysqlconnector://root:root@127.0.0.1:3306/mydb"