【发布时间】:2019-09-03 05:50:27
【问题描述】:
我正在尝试将对象保存在非默认数据库中。我已经配置了第二个连接。
我知道要获取对象是Class.objects.using('the_db').all
但是当我尝试object.using('the_db').save() 时,它不起作用。 (错误:“对象没有属性‘使用’”。
我也试过object.save('the_db'),但它也不起作用。
我怎样才能做到这一点?我找不到正确的语法。
【问题讨论】:
我正在尝试将对象保存在非默认数据库中。我已经配置了第二个连接。
我知道要获取对象是Class.objects.using('the_db').all
但是当我尝试object.using('the_db').save() 时,它不起作用。 (错误:“对象没有属性‘使用’”。
我也试过object.save('the_db'),但它也不起作用。
我怎样才能做到这一点?我找不到正确的语法。
【问题讨论】:
试试object.save(using='the_db')
相关 django 文档:https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#moving-an-object-from-one-database-to-another
【讨论】: