[1.7.x] Fixed #23014 -- Infinite migration regression with unique/index_together.

Backport of 64e75c47ef from master