DC 880 - Foreign keys created and dropped when using Versionable and Searchable behaviours and migration building from YAML

This PR is based on a PR on doctrine/doctrine: https://github.com/doctrine/doctrine1/pull/13.
It couldn't be merged directly due to a merge conflict, which was trivial to fix.