Zend Data Cache returns null when record doesn't exist
Fixes #865.
Fixed foreign key generation bug for pgsql.