#!/usr/bin/env python3
import logging
import sqlalchemy
logging.basicConfig()
logging.getLogger('sqlalchemy').setLevel(logging.DEBUG)
engine = sqlalchemy.create_engine("sqlite:///test.db")
connection = engine.connect()
transaction = connection.begin()
try:
connection.execution_options(autocommit=False).execute("create table test (`id` int NOT NULL);")
connection.execution_options(autocommit=False).execute("create table test (`id` int NOT NULL);")
transaction.commit()
except:
transaction.rollback()
raise
我有这个python脚本。我的期望是,数据库之后没有表测试,但确实如此。我做错了什么/如何回滚create table
?
$ python3 --version
Python 3.5.3