Backport foreign_key/foreign_type to 3.0