python - How to rollback create table with sqlalchemy transaction? (sqlite) -
#!/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
i have python script. expectation be, database doesn't have table test afterwards, does. doing wrong/how can rollback create table
?
$ python3 --version python 3.5.3
Comments
Post a Comment