这显示在我的 vs-studio 终端中:
>>> from app import db #this command is running successful.
>>> db.create_all() # this command not running.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 1039, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 1031, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 962, in get_engine
return connector.get_engine()
File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 555, in get_engine
options = self.get_options(sa_url, echo)
File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 570, in get_options
self._sa.apply_driver_hacks(self._app, sa_url, options)
File "D:\Python\Practice\Flask\env\lib\site-packages\flask_sqlalchemy\__init__.py", line 883, in apply_driver_hacks
if sa_url.drivername.startswith('mysql'):
AttributeError: 'bool' object has no attribute 'drivername'
答案 0 :(得分:0)
在您的代码中:
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://///todo.db" app.config['SQLALCHEMY_DATABASE_URI'] = False app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
删除此行代码:
app.config['SQLALCHEMY_DATABASE_URI'] = False
试试这行代码:
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///todo.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
对于 VSCode 终端:
>>> import app
>>> from app import db
>>> db.create_all()