@transaction.commit_manually(using='other_db')
@transaction.commit_manually
def test(request):
t3 = model.Test3()
t1 = model.Test1()
try:
sid = transaction.savepoint(using='other_db')
t3.save(using='other_db')
sid1 = transaction.savepoint()
t1.save()
transaction.savepoint_commit(sid,using='other_db')
transaction.commit(using='other_db')
transaction.savepoint_commit(sid1)
transaction.commit()
return rest.response("success")
except:
transaction.savepoint_rollback(sid,using='other_db')
transaction.savepoint_rollback(sid1)
transaction.rollback(using='other_db')
transaction.rollback()
return rest.error_response(400, "fail")
test1表的表结构:
delimiter $$
CREATE TABLE `test1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`a` varchar(45) NOT NULL,
`b` varchar(45) DEFAULT NULL,
`c` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `a_UNIQUE` (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8$$
test3表的表结构:
delimiter $$
CREATE TABLE `test3` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`a` varchar(45) NOT NULL,
`b` varchar(45) DEFAULT NULL,
`c` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8$$