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

  • 關於本站
  • 免責聲明