'Tests the AddField operation.'

def test_add_field(self):

    operation = migrations.AddField('Pony', 'height', models.FloatField(null=True, default=5))
    self.assertEqual(operation.describe(), 'Add    field    height    to    Pony')
    (project_state, new_state) = self.make_test_state('test_adfl', operation)
    self.assertEqual(len(new_state.models[('test_adfl', 'pony')].fields), 4)
    field = [f for (n, f) in new_state.models[('test_adfl', 'pony')].fields if (n == 'height')][0]
    self.assertEqual(field.default, 5)
    self.assertColumnNotExists('test_adfl_pony', 'height')
    with connection.schema_editor() as editor:
        operation.database_forwards('test_adfl', editor, project_state, new_state)
    self.assertColumnExists('test_adfl_pony', 'height')
    with connection.schema_editor() as editor:
        operation.database_backwards('test_adfl', editor, new_state, project_state)
    self.assertColumnNotExists('test_adfl_pony', 'height')
    definition = operation.deconstruct()
    self.assertEqual(definition[0], 'AddField')
    self.assertEqual(definition[1], [])
    self.assertEqual(sorted(definition[2]), ['field', 'model_name', 'name'])
