I think you can use "CHECK" for that: CREATE TABLE IF NOT EXISTS "tag_parents" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "from_tag_id" integer NOT NULL REFERENCES "tag" ("id") DEFERRABLE INITIALLY DEFERRED, "to_tag_id" integer NOT NULL REFERENCES "tag" ("id") DEFERRABLE INITIALLY DEFERRED CHECK(from_tag_id <> to_tag_id) );