Moved BooleanField 'required' validation in validate()
Fixed #17158 -- Used a non-ambiguous representation of SQL queries

when a correct representation cannot be obtained.
Merge branch 'master' into 19552