我正在使用Flask和SqlAlchemy。当我尝试运行网站时,为SqlAlchemy创建的数据库似乎混乱了,并且会弹出错误消息,指出存在线程错误。我想知道是否是因为我没有从以前的架构中删除表。我正在使用Linux服务器来尝试运行“ python3”和文件来设置数据库。
我试图从本地驱动器中物理删除该表并重新运行它,但仍然出现此错误。
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import scoped_session
from database_setup import Base, Category, Item
engine = create_engine('sqlite:///database_tables.db')
Base.metadata.bind = engine
Session = sessionmaker()
Session.bind = engine
session = Session()
brushes = Category(id = 1, category_name = 'Brushes')
session.add(brushes)
session.commit()
pencils = Category(id = 2, category_name = 'Pencils')
session.add(pencils)
session.commit()
当我使用Flask处于调试模式时,我单击使用这些行创建的链接,但是单击三下后出现错误
"(sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140244909291264 and this is thread id 140244900898560 [SQL: SELECT category.id AS category_id, category.category_name AS category_category_name FROM category] [parameters: [{}]] (Background on this error at: http://sqlalche.me/e/f405)"