[1.7.x] Fixed #22331 -- Fixed migrations ProjectState to ignore unmanaged models.

Backport of 69d4b1c3ea from master