Fixed bug in foreign keys referencing the same table