Fixed #21852 -- Make migration writer serialize iterators

https://code.djangoproject.com/ticket/21852