docs: def __apply(self, migration=None, run_all=False):
          """
          If a migration is supplied, runs that migration and appends to state.
          If run_all==True, runs all migrations.
          Raises a ValueError if neither "migration" nor "run_all" are provided.
          """
          out = StringIO()
          trace = None
  
          migrate_kwargs = {
              'interactive': False,
              'stdout': out,
              'database': self._database_name,
          }
          if migration is not None:
              migrate_kwargs.update({
                  'app_label': migration[0],
                  'migration_name': migration[1],
              })
          elif not run_all:
              raise ValueError('Either a migration must be provided or "run_all" must be True')
  
          start = self._timer()
          try:
              call_command("migrate", **migrate_kwargs)
          except Exception:
              trace = ''.join(traceback.format_exception(*sys.exc_info()))
          finally:
              end = self._timer()
              successes, failure = self._parse_migrate_output(out.getvalue())
  
              self._migration_state.append({
                  'database': self._database_name,
                  'migration': 'all' if run_all else (migration[0], migration[1]),
                  'duration': end - start,
                  'output': _remove_escape_characters(out.getvalue()),
                  'succeeded_migrations': successes,        # [(app, migration), ...]
                  'failed_migration': failure,              # (app, migration)
                  'traceback': trace,
                  'succeeded': failure is None and trace is None,
              })
  
          if failure is not None:
              raise CommandError("Migration failed for app '{}' - migration '{}'.\n".format(*failure))
          elif trace is not None:
              raise CommandError("Migrations failed unexpectedly. See self.state['traceback'] for details.")