[1.7.x] Fixed #22602 -- Improved code coverage of makemigrations command tests.

Backport of f851a954ac from master