critical code gen fix in migrations

Really need unit tests because this is totally unreliable :(