[1.7.x] Fixed #23731 -- Fixed migrations crash when adding blank GeometryFields on PostGIS.

Thanks raratiru for the report and Claude Paroz for review.

Backport of d6d55368d4 from master