class documentation

class Migration:

Known subclasses: django.contrib.admin.migrations.0001_initial.Migration, django.contrib.admin.migrations.0002_logentry_remove_auto_add.Migration, django.contrib.admin.migrations.0003_logentry_add_action_flag_choices.Migration, django.contrib.auth.migrations.0001_initial.Migration, django.contrib.auth.migrations.0002_alter_permission_name_max_length.Migration, django.contrib.auth.migrations.0003_alter_user_email_max_length.Migration, django.contrib.auth.migrations.0004_alter_user_username_opts.Migration, django.contrib.auth.migrations.0005_alter_user_last_login_null.Migration, django.contrib.auth.migrations.0006_require_contenttypes_0002.Migration, django.contrib.auth.migrations.0007_alter_validators_add_error_messages.Migration, django.contrib.auth.migrations.0008_alter_user_username_max_length.Migration, django.contrib.auth.migrations.0009_alter_user_last_name_max_length.Migration, django.contrib.auth.migrations.0010_alter_group_name_max_length.Migration, django.contrib.auth.migrations.0011_update_proxy_permissions.Migration, django.contrib.auth.migrations.0012_alter_user_first_name_max_length.Migration, django.contrib.contenttypes.migrations.0001_initial.Migration, django.contrib.contenttypes.migrations.0002_remove_content_type_name.Migration, django.contrib.flatpages.migrations.0001_initial.Migration, django.contrib.redirects.migrations.0001_initial.Migration, django.contrib.redirects.migrations.0002_alter_redirect_new_path_help_text.Migration, django.contrib.sessions.migrations.0001_initial.Migration, django.contrib.sites.migrations.0001_initial.Migration, django.contrib.sites.migrations.0002_alter_domain_unique.Migration

View In Hierarchy

The base class for all migrations.

Migration files will import this from django.db.migrations.Migration and subclass it as a class called Migration. It will have one or more of the following attributes:

  • operations: A list of Operation instances, probably from django.db.migrations.operations
  • dependencies: A list of tuples of (app_path, migration_name)
  • run_before: A list of tuples of (app_path, migration_name)
  • replaces: A list of migration_names

Note that all migrations come out of migrations and into the Loader or Graph as instances, having been initialized with their app label and name.

Method __eq__ Undocumented
Method __hash__ Undocumented
Method __init__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Method apply Take a project_state representing all migrations prior to this one and a schema_editor for a live database and apply the migration in a forwards order.
Method mutate​_state Take a ProjectState and return a new one with the migration's operations applied to it. Preserve the original object state by default and return a mutated state from a copy.
Method suggest​_name Suggest a name for the operations this migration might represent. Names are not guaranteed to be unique, but put some effort into the fallback name to avoid VCS conflicts if possible.
Method unapply Take a project_state representing all migrations prior to this one and a schema_editor for a live database and apply the migration in a reverse order.
Class Variable atomic Undocumented
Class Variable initial Undocumented
Instance Variable app​_label Undocumented
Instance Variable dependencies Undocumented
Instance Variable name Undocumented
Instance Variable operations Undocumented
Instance Variable replaces Undocumented
Instance Variable run​_before Undocumented
def __eq__(self, other):

Undocumented

def __hash__(self):

Undocumented

def __init__(self, name, app_label):

Undocumented

def __repr__(self):

Undocumented

def __str__(self):

Undocumented

def apply(self, project_state, schema_editor, collect_sql=False):

Take a project_state representing all migrations prior to this one and a schema_editor for a live database and apply the migration in a forwards order.

Return the resulting project state for efficient reuse by following Migrations.

def mutate_state(self, project_state, preserve=True):
Take a ProjectState and return a new one with the migration's operations applied to it. Preserve the original object state by default and return a mutated state from a copy.
def suggest_name(self):
Suggest a name for the operations this migration might represent. Names are not guaranteed to be unique, but put some effort into the fallback name to avoid VCS conflicts if possible.
def unapply(self, project_state, schema_editor, collect_sql=False):

Take a project_state representing all migrations prior to this one and a schema_editor for a live database and apply the migration in a reverse order.

The backwards migration process consists of two phases:

  1. The intermediate states from right before the first until right after the last operation inside this migration are preserved.
  2. The operations are applied in reverse order using the states recorded in step 1.
atomic: bool =

Undocumented

initial =

Undocumented

app_label =

Undocumented

dependencies =
overridden in django.contrib.admin.migrations.0001_initial.Migration, django.contrib.admin.migrations.0002_logentry_remove_auto_add.Migration, django.contrib.admin.migrations.0003_logentry_add_action_flag_choices.Migration, django.contrib.auth.migrations.0001_initial.Migration, django.contrib.auth.migrations.0002_alter_permission_name_max_length.Migration, django.contrib.auth.migrations.0003_alter_user_email_max_length.Migration, django.contrib.auth.migrations.0004_alter_user_username_opts.Migration, django.contrib.auth.migrations.0005_alter_user_last_login_null.Migration, django.contrib.auth.migrations.0006_require_contenttypes_0002.Migration, django.contrib.auth.migrations.0007_alter_validators_add_error_messages.Migration, django.contrib.auth.migrations.0008_alter_user_username_max_length.Migration, django.contrib.auth.migrations.0009_alter_user_last_name_max_length.Migration, django.contrib.auth.migrations.0010_alter_group_name_max_length.Migration, django.contrib.auth.migrations.0011_update_proxy_permissions.Migration, django.contrib.auth.migrations.0012_alter_user_first_name_max_length.Migration, django.contrib.contenttypes.migrations.0001_initial.Migration, django.contrib.contenttypes.migrations.0002_remove_content_type_name.Migration, django.contrib.flatpages.migrations.0001_initial.Migration, django.contrib.redirects.migrations.0001_initial.Migration, django.contrib.redirects.migrations.0002_alter_redirect_new_path_help_text.Migration, django.contrib.sessions.migrations.0001_initial.Migration, django.contrib.sites.migrations.0001_initial.Migration, django.contrib.sites.migrations.0002_alter_domain_unique.Migration

Undocumented

name =

Undocumented

operations =
overridden in django.contrib.admin.migrations.0001_initial.Migration, django.contrib.admin.migrations.0002_logentry_remove_auto_add.Migration, django.contrib.admin.migrations.0003_logentry_add_action_flag_choices.Migration, django.contrib.auth.migrations.0001_initial.Migration, django.contrib.auth.migrations.0002_alter_permission_name_max_length.Migration, django.contrib.auth.migrations.0003_alter_user_email_max_length.Migration, django.contrib.auth.migrations.0004_alter_user_username_opts.Migration, django.contrib.auth.migrations.0005_alter_user_last_login_null.Migration, django.contrib.auth.migrations.0006_require_contenttypes_0002.Migration, django.contrib.auth.migrations.0007_alter_validators_add_error_messages.Migration, django.contrib.auth.migrations.0008_alter_user_username_max_length.Migration, django.contrib.auth.migrations.0009_alter_user_last_name_max_length.Migration, django.contrib.auth.migrations.0010_alter_group_name_max_length.Migration, django.contrib.auth.migrations.0011_update_proxy_permissions.Migration, django.contrib.auth.migrations.0012_alter_user_first_name_max_length.Migration, django.contrib.contenttypes.migrations.0001_initial.Migration, django.contrib.contenttypes.migrations.0002_remove_content_type_name.Migration, django.contrib.flatpages.migrations.0001_initial.Migration, django.contrib.redirects.migrations.0001_initial.Migration, django.contrib.redirects.migrations.0002_alter_redirect_new_path_help_text.Migration, django.contrib.sessions.migrations.0001_initial.Migration, django.contrib.sites.migrations.0001_initial.Migration, django.contrib.sites.migrations.0002_alter_domain_unique.Migration

Undocumented

replaces =

Undocumented

run_before =

Undocumented