django 多数据源中使用事务注意事项
2021-10-20 本文已影响0人
高峥
# 数据库配置
DATABASES = {
"default": {
"ENGINE": "mainsys.mysqlpool",
"NAME": "el_product",
"USER": "select_user",
"PASSWORD": "select_user@321",
"HOST": "10.32",
},
"bt_investment": {
"ENGINE": "mainsys.mysqlpool",
"NAME": "",
"USER": "aaa",
"PASSWORD": "aaa",
"HOST": "10.32",
"ATOMIC_REQUESTS":True
},
"industrychain": {
"ENGINE": "mainsys.mysqlpool",
"NAME": "industrychain",
"USER": "select_user",
"PASSWORD": "select_user@321",
"HOST": "10.32",
},
}
...
...
...
with transaction.atomic(using="bt_investment"): # 指定数据源,可以在python代码的任何位置使用
for obj in execel_data_formart: