我使用MySQL8.0,使用not引擎,使用peewee 3.14版本,我使用peewee事务提交,在没有执行提交的情况下,我看到数据已经写入数据库,但我没有执行db.commit(),而是在MySQL中手动执行命令。如果我不执行commit,我将无法编写。但是,在使用peewee事务提交时会出现不一致。我的密码怎么了?
db =db = MySQLDatabase("address", host="127.0.0.1", port=3306, user="root", passwd="xxx",autocommit=False,autorollback=True)
with db.manual_commit():
db.begin()
Spead.create(dis="test",number="test",value=333)发布于 2020-11-20 14:43:43
您还在peewee问题跟踪器上打开了一篇文章,我在这里发表了以下评论:
我看到数据已经写入数据库了。
假设您的意思是您使用了一个单独的连接,并在由peewee连接提交数据之前看到了它?您可以检查已读取的隔离设置。
当我运行以下脚本时,我得到了预期的输出--第二个连接在调用commit之前不会看到未提交的行:
from peewee import *
db = MySQLDatabase('peewee_test')
db2 = MySQLDatabase('peewee_test') # 2nd connection
class Reg(Model):
key = TextField()
class Meta:
database = db
class Reg2(Reg): # model class for accessing table using 2nd conn
class Meta:
database = db2
table_name = 'reg'
db.create_tables([Reg])
with db.manual_commit() as tx:
db.begin()
Reg.create(key='k1') # create a row using first conn
db2.connect() # query table using 2nd conn
print('is "k1" visible to conn2 BEFORE commit?')
print('rows in "reg" table: %s' % Reg2.select().count())
db.commit()
print('is "k1" visible to conn2 AFTER commit?')
print('rows in "reg" table: %s' % Reg2.select().count())
db2.close()
db.drop_tables([Reg])输出:
is "k1" visible to conn2 BEFORE commit?
rows in "reg" table: 0
is "k1" visible to conn2 AFTER commit?
rows in "reg" table: 1https://stackoverflow.com/questions/64931303
复制相似问题