'Tests the AddField operation with a ManyToManyField.'

def test_add_field_m2m(self):

    project_state = self.set_up_test_model('test_adflmm', second_model=True)
    operation = migrations.AddField('Pony', 'stables', models.ManyToManyField('Stable', related_name='ponies'))
    new_state = project_state.clone()
    operation.state_forwards('test_adflmm', new_state)
    self.assertEqual(len(new_state.models[('test_adflmm', 'pony')].fields), 4)
    self.assertTableNotExists('test_adflmm_pony_stables')
    with connection.schema_editor() as editor:
        operation.database_forwards('test_adflmm', editor, project_state, new_state)
    self.assertTableExists('test_adflmm_pony_stables')
    self.assertColumnNotExists('test_adflmm_pony', 'stables')
    with atomic():
        Pony = new_state.apps.get_model('test_adflmm', 'Pony')
        p = Pony.objects.create(pink=False, weight=4.55)
        p.stables.create()
        self.assertEqual(p.stables.count(), 1)
        p.stables.all().delete()
    with connection.schema_editor() as editor:
        operation.database_backwards('test_adflmm', editor, new_state, project_state)
    self.assertTableNotExists('test_adflmm_pony_stables')
