'Validates the given app, raising CommandError for any errors.
If app is None, then this will validate all installed apps.'

def validate(self, app=None, display_num_errors=False):

    from django.core.management.validation import get_validation_errors
    s = StringIO()
    num_errors = get_validation_errors(s, app)
    if num_errors:
        s.seek(0)
        error_text = s.read()
        raise CommandError((u'One    or    more    models    did    not    validate:\n%s' % error_text))
    if display_num_errors:
        self.stdout.write((u'%s    error%s    found' % (num_errors, (u'' if (num_errors == 1) else u's'))))
