将多位表路由到 django 中的非默认数据库
我通过 数据库路由器使用 django 的多数据库支持 将某些模型划分为 1 db,将其他模型划分为另一个。 (请注意,我是否“应该”这样做与我的问题无关。)我在同一个非默认数据库中有 2 个模型,并且它们具有多对多关系(通过其中一个模型上的 ManyToManyField) 。我希望由于 m2m 关系而创建的表与 2 个模型在同一个数据库中创建,但似乎没有一种简单的方法来做到这一点 - 数据库路由器功能仅允许基于一个模型。两个模型的路由均正确,但 m2m 表的路由不正确。
我可以设置 m2m 字段以使用 中间模型,这样我可以将该模型路由到适当的数据库,但如果我可以避免它,我宁愿不这样做,因为它消除了通常可用于的简单添加、删除等功能M2M 领域。
还有其他方法可以做到这一点吗?如果不是,这是否值得创建票证?
I'm using django's multi-db support via database routers to partition certain models to 1 db, and others into another. (Note that whether I "should" be doing that is irrelevant to my question.) I have 2 models in the same, non-default database, and they have a many-to-many relationship (via a ManyToManyField on one of them). I would like the table that gets created due to the m2m relationship to be created in the same db as the 2 models, but there doesn't seem to be a straightforward way of doing that -- the database routers functionality only allows routing based on a model. Both models are being routed correctly, but not the m2m table.
I could set up the m2m field to use an intermediate model so I can route that model to the appropriate db, but I'd rather not do that if I can avoid it since it eliminates the simple add, remove, etc functions normally available for m2m fields.
Is there another way to do this? If not, is this something worth creating a ticket about?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论