'Try to execute this command, performing model validation if
needed (as controlled by the attribute
``self.requires_model_validation``). If the command raises a
``CommandError``, intercept it and print it sensibly to
stderr.'

def execute(self, *args, **options):

    if self.can_import_settings:
        try:
            from django.utils import translation
            translation.activate('en-us')
        except ImportError as e:
            sys.stderr.write(smart_str(self.style.ERROR(('Error:    %s\n' % e))))
            sys.exit(1)
    try:
        self.stdout = options.get('stdout', sys.stdout)
        self.stderr = options.get('stderr', sys.stderr)
        if self.requires_model_validation:
            self.validate()
        output = self.handle(*args, **options)
        if output:
            if self.output_transaction:
                from django.db import connections, DEFAULT_DB_ALIAS
                connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
                if connection.ops.start_transaction_sql():
                    self.stdout.write((self.style.SQL_KEYWORD(connection.ops.start_transaction_sql()) + '\n'))
            self.stdout.write(output)
            if self.output_transaction:
                self.stdout.write((('\n' + self.style.SQL_KEYWORD('COMMIT;')) + '\n'))
    except CommandError as e:
        self.stderr.write(smart_str(self.style.ERROR(('Error:    %s\n' % e))))
        sys.exit(1)
