I have a legacy db table which has composite primary key. I don\'t think I will be able to change the structure to include a surrogate key, as there is some code written tha
The accepted answer is fine. However, it's a little old. unique_together may be deprecated in favor of UniqueConstraint. So, the better way of doing this would be;
UniqueConstraint(fields = ['key1', 'key2'], name = 'constraint_name')