Closed wakakaaaabbbb closed 3 years ago
因为在初始化数据库的时候在状态表中插入两个状态,使用中文命名的。代码如下
Blogin/blogin/__init__.py
文件
@app.cli.command()
def admin():
try:
db.drop_all()
db.create_all()
Role.init_role()
States.init_states()
# 省略后续代码
/Blogin/blogin/models.py
文件
@staticmethod
def init_states():
s1 = States(name='正常')
s2 = States(name='禁用')
db.session.add(s1)
db.session.add(s2)
db.session.commit()
所以报这个错误应该是你数据库的编码没有设置为utf8
。
我高估我自己了哈哈哈,下面是error
(venv) D:\project\createblog\Blogin>flask admin
Traceback (most recent call last):
File "C:\python385\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\python385\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\project\createblog\Blogin\venv\Scripts\flask.exe__main.py", line 7, in
mysql> show variables like '%char%' -> ; +--------------------------+----------------------------------------------+ | Variable_name | Value | +--------------------------+----------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | D:\mysql\mysql-8.0.20-winx64\share\charsets\ | +--------------------------+----------------------------------------------+ 8 rows in set, 1 warning (0.00 sec)
问题解决了吗? 你可以手动插入中文数据到你的数据库试试,看看会不会报错。
可能是你的 .env文件的编码不对 看你的报错还没到数据库那一步
也不是env编码的问题,下班再看看hhh
please confirm your database encode is utf8.