[1.7.x] Avoided unneeded calls to state.render() in migrations.

Backport of 19ae13d9ed76208b29bb40aec1bfff8196aa7331 from master