Run migrate

    Execute the Django-Admin migrate command (requires Django 1.7 or higher).

    .. versionadded:: Neon

    settings_module
        Specifies the settings module to use.
        The settings module should be in Python package syntax, e.g. mysite.settings.
        If this isn’t provided, django-admin will use the DJANGO_SETTINGS_MODULE
        environment variable.

    app_label
        Specific app to run migrations for, instead of all apps.
        This may involve running other apps’ migrations too, due to dependencies.

    migration_name
        Named migration to be applied to a specific app.
        Brings the database schema to a state where the named migration is applied,
        but no later migrations in the same app are applied. This may involve
        unapplying migrations if you have previously migrated past the named migration.
        Use the name zero to unapply all migrations for an app.

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    database
        Database to migrate. Defaults to 'default'.

    pythonpath
        Adds the given filesystem path to the Python import search path.
        If this isn’t provided, django-admin will use the PYTHONPATH environment variable.

    env
        A list of environment variables to be set prior to execution.

        Example:

        .. code-block:: yaml

            module.run:
              - name: django.migrate
              - settings_module: my_django_app.settings
              - env:
                - DATABASE_USER: 'mydbuser'

    noinput
        Suppresses all user prompts. Defaults to True.

    runas
        The user name to run the command as.

    CLI Example:

    .. code-block:: bash

        salt '*' django.migrate <settings_module>
        salt '*' django.migrate <settings_module> <app_label>
        salt '*' django.migrate <settings_module> <app_label> <migration_name>

def migrate(settings_module,
           app_label=None,
           migration_name=None,
           bin_env=None,
           database=None,
           pythonpath=None,
           env=None,
           noinput=True,
           runas=None):
    '''
    Run migrate

    Execute the Django-Admin migrate command (requires Django 1.7 or higher).

    .. versionadded:: Neon

    settings_module
        Specifies the settings module to use.
        The settings module should be in Python package syntax, e.g. mysite.settings.
        If this isn’t provided, django-admin will use the DJANGO_SETTINGS_MODULE
        environment variable.

    app_label
        Specific app to run migrations for, instead of all apps.
        This may involve running other apps’ migrations too, due to dependencies.

    migration_name
        Named migration to be applied to a specific app.
        Brings the database schema to a state where the named migration is applied,
        but no later migrations in the same app are applied. This may involve
        unapplying migrations if you have previously migrated past the named migration.
        Use the name zero to unapply all migrations for an app.

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    database
        Database to migrate. Defaults to 'default'.

    pythonpath
        Adds the given filesystem path to the Python import search path.
        If this isn’t provided, django-admin will use the PYTHONPATH environment variable.

    env
        A list of environment variables to be set prior to execution.

        Example:

        .. code-block:: yaml

            module.run:
              - name: django.migrate
              - settings_module: my_django_app.settings
              - env:
                - DATABASE_USER: 'mydbuser'

    noinput
        Suppresses all user prompts. Defaults to True.

    runas
        The user name to run the command as.

    CLI Example:

    .. code-block:: bash

        salt '*' django.migrate <settings_module>
        salt '*' django.migrate <settings_module> <app_label>
        salt '*' django.migrate <settings_module> <app_label> <migration_name>
    '''
    args = []
    kwargs = {}
    if database:
        kwargs['database'] = database
    if noinput:
        args.append('noinput')

    if app_label and migration_name:
        cmd = "migrate {0} {1}".format(app_label, migration_name)
    elif app_label:
        cmd = "migrate {0}".format(app_label)
    else:
        cmd = 'migrate'

    return command(settings_module,
                   cmd,
                   bin_env,
                   pythonpath,
                   env,
                   runas,
                   *args, **kwargs)