django_evolution.mutations.change_field

Mutation that changes attributes on a field.

New in version 2.2.

Classes

ChangeField(model_name, field_name[, ...])

A mutation that changes attributes on a field on a model.

class django_evolution.mutations.change_field.ChangeField(model_name, field_name, field_type=None, initial=None, **field_attrs)

Bases: BaseModelFieldMutation

A mutation that changes attributes on a field on a model.

Changed in version 2.2:

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

Initialize the mutation.

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

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

  • field_type (type, optional) –

    The new type of the field. This must be a subclass of Field.

    New in version 2.2.

  • 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 change attributes for 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 change on the mutator.

This will instruct the mutator to change attributes on a 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.