我的代码如下:
In [9]: mylist = [1, 44, 56, 2]
In [10]: total = sum(i for i in mylist)
In [11]: total
Out[11]: 103
一切正常,直到重新启动数据库。然后需要from sqlalchemy import create_engine, Column, String, Integer
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import as_declarative
db_url = f'mysql://{user}:{password}@{host}:{port}/{database}'
engine = create_engine(db_url)
db = scoped_session(sessionmaker(bind=engine))
@as_declarative()
class Base(object):
id = Column(Integer, primary_key=True)
query = db.query_property()
class User(Base):
email = Column(String(128), unique=True, nullable=False)
def __repr__(self):
return f'<User {self.email}>'
。
示例:
db.rollback()
即使重新连接数据库后,我也希望一切正常。你知道怎么做吗?