fixed indexed foreign keys with references. added some validations to th...

...e models