          if hasattr(model, "_default_manager"):
              default_manager_name = force_text(model._default_manager.name)
              # Make sure the default manager is always the first
              if model._default_manager.use_in_migrations:
                  reconstruct_manager(model._default_manager)
              else:
                  # Force this manager to be the first and thus default
                  managers_mapping[default_manager_name] = (0, models.Manager())
              for manager in model._meta.managers:
                  if manager.name == "_base_manager" or not manager.use_in_migrations:
 
</s> remove         def reconstruct_manager(mgr):
            as_manager, manager_path, qs_path, args, kwargs = mgr.deconstruct()
            if as_manager:
                qs_class = import_string(qs_path)
                instance = qs_class.as_manager()
            else:
                manager_class = import_string(manager_path)
                instance = manager_class(*args, **kwargs)
            # We rely on the ordering of the creation_counter of the original
            # instance
            name = force_text(mgr.name)
            managers_mapping[name] = (mgr.creation_counter, instance)

        if hasattr(model, "_default_manager"):
            default_manager_name = force_text(model._default_manager.name)
            # Make sure the default manager is always the first
 </s> add         # Make sure the default manager is always first since ordering chooses
        # the default manager.
        if not model._default_manager.auto_created: </s> remove                 # Force this manager to be the first and thus default
                managers_mapping[default_manager_name] = (0, models.Manager())
            for manager in model._meta.managers:
                if manager.name == "_base_manager" or not manager.use_in_migrations:
                    continue
                reconstruct_manager(manager)
            # Sort all managers by their creation counter but take only name and
            # instance for further processing
            managers = [
                (name, instance) for name, (cc, instance) in
                sorted(managers_mapping.items(), key=lambda v: v[1])
            ]
            # If the only manager on the model is the default manager defined
            # by Django (`objects = models.Manager()`), this manager will not
            # be added to the model state.
            if managers == [('objects', models.Manager())]:
                managers = []
        else:
            managers = []
 </s> add                 default_manager = models.Manager()
                default_manager.model = model
                default_manager.name = model._default_manager.name
            managers.append((force_text(default_manager.name), default_manager))

        for manager in model._meta.managers:
            if manager.use_in_migrations and manager is not model._default_manager:
                manager = copy.copy(manager)
                manager._set_creation_counter()
                managers.append((force_text(manager.name), manager)) </s> remove def can_use_for_related_field(manager_class):
    return manager_class is Manager or getattr(manager_class, 'use_for_related_fields', False)


def ensure_default_manager(model):
    """
    Ensures that a Model subclass contains a default manager and sets the
    _default_manager and _base_manager attributes on the class.
    """

    if not model._meta.managers:
        if any(f.name == 'objects' for f in model._meta.fields):
            raise ValueError(
                "Model %s must specify a custom Manager, because it has a "
                "field named 'objects'" % model.__name__
            )
        model.add_to_class('objects', Manager())

    model._default_manager = model._meta.managers[0]

    # Just alias _base_manager if default manager is suitable.
    if can_use_for_related_field(model._default_manager.__class__):
        model._base_manager = model._default_manager

    # Otherwise search for a suitable manager type in the default manager MRO.
    else:
        for base_manager_class in model._default_manager.__class__.mro()[1:]:
            if can_use_for_related_field(base_manager_class):
                model._base_manager = base_manager_class()
                model._base_manager.name = '_base_manager'
                model._base_manager.model = model
                break
        else:
            raise ValueError("Could not find a suitable base manager.")


 </s> add  </s> remove 2. The default manager on a class is either the first manager declared on the
   class, if that exists, or the default manager of the first parent class in
   the parent hierarchy, if that exists. If no manager is explicitly declared,
   Django automatically creates the `objects` manager and it becomes the default
   manager.
 </s> add #. If no managers are declared on a model and/or its parents, Django
   automatically creates the ``objects`` manager.

#. The default manager on a class is either the one chosen with
   :attr:`Meta.default_manager_name
   <django.db.models.Options.default_manager_name>`, or the first manager
   declared on the model, or the default manager of the first parent model. </s> remove         manager = self.field.remote_field.model._default_manager
        # If the related manager indicates that it should be used for
        # related fields, respect that.
        if not getattr(manager, 'use_for_related_fields', False):
            manager = self.field.remote_field.model._base_manager
 </s> add         related_model = self.field.remote_field.model

        if (not related_model._meta.base_manager_name and
                getattr(related_model._default_manager, 'use_for_related_fields', False)):
            if not getattr(related_model._default_manager, 'silence_use_for_related_fields_deprecation', False):
                warnings.warn(
                    "use_for_related_fields is deprecated, instead "
                    "set Meta.base_manager_name on '{}'.".format(related_model._meta.label),
                    RemovedInDjango20Warning, 2
                )
            manager = related_model._default_manager
        else:
            manager = related_model._base_manager

                default_manager = copy.copy(model._default_manager)
                default_manager._set_creation_counter()

            # If the default manager doesn't have `use_in_migrations = True`,
            # shim a default manager so another manager isn't promoted in its
            # place.
          if hasattr(model, "_default_manager"):
              default_manager_name = force_text(model._default_manager.name)
              # Make sure the default manager is always the first
              if model._default_manager.use_in_migrations:
                default_manager = copy.copy(model._default_manager)
                default_manager._set_creation_counter()

            # If the default manager doesn't have `use_in_migrations = True`,
            # shim a default manager so another manager isn't promoted in its
            # place.
              else:
                  # Force this manager to be the first and thus default
                  managers_mapping[default_manager_name] = (0, models.Manager())
              for manager in model._meta.managers:
                  if manager.name == "_base_manager" or not manager.use_in_migrations:
keep keep keep keep replace keep keep keep keep keep
 Fixed #10506, #13793, #14891, #25201 -- Introduced new APIs to specify models' default and base managers.

This deprecates use_for_related_fields.

Old API:

class CustomManager(models.Model):
    use_for_related_fields = True

class Model(models.Model):
    custom_manager = CustomManager()

New API:

class Model(models.Model):
    custom_manager = CustomManager()

    class Meta:
        base_manager_name = 'custom_manager'

Refs #20932, #25897.

Thanks Carl Meyer for the guidance throughout this work.
Thanks Tim Graham for writing the docs. 
django/db/migrations/state.py