workspace/python/bbs python manage.py db migrate ✔
Traceback (most recent call last):
File "manage.py", line 13, in
manager.run()
File "/Users/yuanting/venv/lib/python3.7/site-packages/flask_script/__init__.py", line 417, in run
result = self.handle(argv[0], argv[1:])
File "/Users/yuanting/venv/lib/python3.7/site-packages/flask_script/__init__.py", line 386, in handle
res = handle(*args, **config)
File "/Users/yuanting/venv/lib/python3.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "/Users/yuanting/venv/lib/python3.7/site-packages/flask_migrate/__init__.py", line 95, in wrapped
f(*args, **kwargs)
File "/Users/yuanting/venv/lib/python3.7/site-packages/flask_migrate/__init__.py", line 215, in migrate
version_path=version_path, rev_id=rev_id)
File "/Users/yuanting/venv/lib/python3.7/site-packages/alembic/command.py", line 197, in revision
script_directory.run_env()
File "/Users/yuanting/venv/lib/python3.7/site-packages/alembic/script/base.py", line 475, in run_env
util.load_python_file(self.dir, "env.py")
File "/Users/yuanting/venv/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 90, in load_python_file
module = load_module_py(module_id, path)
File "/Users/yuanting/venv/lib/python3.7/site-packages/alembic/util/compat.py", line 177, in load_module_py
spec.loader.exec_module(module)
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "migrations/env.py", line 96, in
run_migrations_online()
File "migrations/env.py", line 81, in run_migrations_online
with connectable.connect() as connection:
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2193, in connect
return self._connection_cls(self, **kwargs)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 103, in __init__
else engine.raw_connection()
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2293, in raw_connection
self.pool.unique_connection, _connection
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2262, in _wrap_pool_connect
return fn()
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 303, in unique_connection
return _ConnectionFairy._checkout(self)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 760, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
rec = pool._do_get()
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 238, in _do_get
return self._create_connection()
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
return _ConnectionRecord(self)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
self.__connect(first_connect_check=True)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 639, in __connect
connection = pool._invoke_creator(self)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/Users/yuanting/venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 451, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/Users/yuanting/venv/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/Users/yuanting/venv/lib/python3.7/site-packages/pymysql/connections.py", line 283, in __init__
self.encoding = charset_by_name(self.charset).encoding
AttributeError: 'NoneType' object has no attribute 'encoding'
解决方案:
如下所示,数据库连接url中添加数据设置编码为utf8参数
DB_URI = “mysql+pymysql://root:[email protected]:3306/bbs?charset=utf8”