在 Django 的数据库中获取唯一的约束名称

Get unique together constraint name in db in Django

如何在 Django 中获取唯一在一起约束的名称?

它似乎是随机生成的,例如book_membership_collection_id_order_c52e778f_uniq,我需要以编程方式获取此名称以使用 RunSQL

执行某些操作

我发现可以通过

connection.schema_editor()._constraint_names(MYModel, ['col1', 'col2'], unique=True)