我正在尝试将对象保存在非默认数据库中。我已经配置了第二个连接。
我知道为了获取对象,它是 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
关于python - Django:不同数据库中的 save() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55652043/