Fixed bug with foreign keys