fixed database problems with foreign keys