Here is an example of how it should look. Suppose you have a model:
class UserConnectionRequest(models.Model): sender = models.ForeignKey(UserProfile, related_name='sent_requests') recipient = models.ForeignKey(UserProfile, related_name='received_requests') connection_type = models.PositiveIntegerField(verbose_name=_(u'Connection type'), \ choices=UserConnectionType.choices()) class Meta: unique_together = (("sender", "recipient", "connection_type"),)
Running sqlall returns:
CREATE TABLE "users_userconnectionrequest" ( "id" serial NOT NULL PRIMARY KEY, "sender_id" integer NOT NULL REFERENCES "users_userprofile" ("id") DEFERRABLE INITIALLY DEFERRED, "recipient_id" integer NOT NULL REFERENCES "users_userprofile" ("id") DEFERRABLE INITIALLY DEFERRED, "connection_type" integer, UNIQUE ("sender_id", "recipient_id", "connection_type") )
When this model correctly synchronizes with the database, it has a unique restriction (postgres):
CONSTRAINT users_userconnectionrequest_sender_id_2eec26867fa22bfa_uniq UNIQUE (sender_id, recipient_id, connection_type),
source share