Fix port script to correctly handle foreign key constraints. Broke in v1.21.0.