Repository: django/django
File: tests/migrations/test_autodetector.py (Python)

Code before:
            name="pk",
            model_name="foo",
        )
        self.assertOperationAttributes(
            changes,
            "app",
            0,
            1,
            name="id",
            model_name="foo",
            preserve_default=True,
        )

    def test_m2m_target_change_generates_remove_and_add(self):
        # Initial state: Author has M2M to Publisher
        before = [
            self.publisher,
            self.magazine,
            self.author_with_m2m,
        ]
        # After state: Author has M2M to Magazine
        after = [
            self.publisher,
            self.magazine,
            self.author_with_m2m_magazine,
        ]
        changes = self.get_changes(before, after)
        self.assertNumberMigrations(changes, "testapp", 1)
        self.assertOperationTypes(changes, "testapp", 0, ["RemoveField", "AddField"])
        self.assertOperationAttributes(
            changes,
            "testapp",
            0,
            0,
            name="publishers",
            model_name="author",
        )
        self.assertOperationAttributes(
            changes,
            "testapp",
            0,
            1,
            name="publishers",
            model_name="author",
        )


class MigrationSuggestNameTests(SimpleTestCase):
    def test_no_operations(self):
        class Migration(migrations.Migration):
            operations = []

Review comment (security):
```suggestion
        after = [
            self.publisher,
            self.other_publisher,
            ModelState(
                "testapp",
                "Author",
                [
                    ("id", models.AutoField(primary_key=True)),
                    # Repoint m2m to self.other_publisher.
                    ("publishers", models.ManyToManyField("testapp.OtherPublisher")),
                ],
            ),
        ]
```

Code after:
            0,
            1,
            name="id",
            model_name="foo",
            preserve_default=True,
        )

    def test_remove_composite_pk(self):
        before = [
            ModelState(
                "app",
                "foo",
                [
                    ("pk", models.CompositePrimaryKey("foo_id", "bar_id")),
                    ("id", models.IntegerField()),
                ],
            ),
        ]
        after = [
            ModelState(
                "app",
                "foo",
                [
                    ("id", models.AutoField(primary_key=True)),
                ],
            ),
        ]

        changes = self.get_changes(before, after)
        self.assertNumberMigrations(changes, "app", 1)
        self.assertOperationTypes(changes, "app", 0, ["RemoveField", "AlterField"])
        self.assertOperationAttributes(
            changes,
            "app",
            0,
            0,
            name="pk",
            model_name="foo",
        )
        self.assertOperationAttributes(
            changes,
            "app",
            0,
            1,
            name="id",
            model_name="foo",
            preserve_default=True,
        )


class MigrationSuggestNameTests(SimpleTestCase):