Fixed foreign key constraints and made compatible with Oracle.