美文网首页
django 多数据源中使用事务注意事项

django 多数据源中使用事务注意事项

作者: 高峥 | 来源:发表于2021-10-20 16:22 被阅读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:

相关文章

网友评论

      本文标题:django 多数据源中使用事务注意事项

      本文链接:https://www.haomeiwen.com/subject/gydhmktx.html