logo
  • 教程列表
  • SO官方文档
  • 数据库路由器
    • 添加数据库路由文件
    • 在代码中指定不同的数据库
  1. StackOverflow 文档
  2. Django 教程
  3. 数据库路由器
  4. 在代码中指定不同的数据库

在代码中指定不同的数据库

Created: November-22, 2018

正常的 obj.save() 方法将使用默认数据库,或者如果使用数据库路由器,它将使用 db_for_write 中指定的数据库。你可以使用以下方法重写它:

obj.save(using='other_db')
obj.delete(using='other_db')

同样,阅读:

MyModel.objects.using('other_db').all()
  • 添加数据库路由文件

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明