django_evolution.mutations.add_field

Mutation that adds a field to a model.

New in version 2.2.

Classes

AddField(model_name, field_name, field_type)

A mutation that adds a field to a model.

class django_evolution.mutations.add_field.AddField(model_name, field_name, field_type, initial=None, **field_attrs)

Bases: BaseModelFieldMutation

A mutation that adds a field to a model.

Changed in version 2.2: Moved into the django_evolution.mutations.add_field module.

simulation_failure_error = 'Cannot add the field "%(field_name)s" to model "%(app_label)s.%(model_name)s".'
__init__(model_name, field_name, field_type, initial=None, **field_attrs)

Initialize the mutation.

Parameters:
  • model_name (unicode) – The name of the model to add the field to.

  • field_name (unicode) – The name of the new field.

  • field_type (cls) – The field class to use. This must be a subclass of django.db.models.Field.

  • initial (object, optional) – The initial value for the field. This is required if non-null.

  • **field_attrs (dict) – Attributes to set on the field.

get_hint_params()

Return parameters for the mutation’s hinted evolution.

Returns:

A list of parameter strings to pass to the mutation’s constructor in a hinted evolution.

Return type:

list of unicode

simulate(simulation)

Simulate the mutation.

This will alter the database schema to add the specified field.

Parameters:

simulation (Simulation) – The state for the simulation.

Raises:

django_evolution.errors.SimulationFailure – The simulation failed. The reason is in the exception’s message.

mutate(mutator, model)

Schedule a field addition on the mutator.

This will instruct the mutator to add a new field on a model. It will be scheduled and later executed on the database, if not optimized out.

Parameters:
  • mutator (django_evolution.mutators.ModelMutator) – The mutator to perform an operation on.

  • model (MockModel) – The model being mutated.

add_column(mutator, model)

Add a standard column to the model.

Parameters:
  • mutator (django_evolution.mutators.ModelMutator) – The mutator to perform an operation on.

  • model (MockModel) – The model being mutated.

add_m2m_table(mutator, model)

Add a ManyToMany column to the model and an accompanying table.

Parameters:
  • mutator (django_evolution.mutators.ModelMutator) – The mutator to perform an operation on.

  • model (MockModel) – The model being mutated.