A possible solution is to use a trigger.
create trigger bi_foo before insert on foo
for each row
begin
if exists(select 1 from foo where bar1 = NEW.bar2 and bar2 = NEW.bar1)
then
signal sqlstate '50000' set message_text="Oops";
end if;
end
This will work:
insert into foo values (1, 2), (3, 4), (5, 6);
insert into foo values (3, 2), (3, 5), (1, 6);
This will fail:
mysql> insert into foo values (2, 1);
ERROR 1644 (50000): Oops