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

Code before:
            model_name="foo",
            preserve_default=True,
        )

    def test_m2m_target_change_generates_remove_and_add(self):
        # Initial state: Author has M2M to Book
        before = [
            ModelState(
                "testapp",
                "Book",
                [("id", models.AutoField(primary_key=True))],
            ),
            ModelState(
                "testapp",
                "Magazine",
                [("id", models.AutoField(primary_key=True))],
            ),
            ModelState(
                "testapp",
                "Author",
                [
                    ("id", models.AutoField(primary_key=True)),
                    ("readings", models.ManyToManyField("testapp.Book")),
                ],
            ),
        ]
        # After state: Author has M2M to Magazine (same field name 'readings')
        after = [
            ModelState(
                "testapp",
                "Book",
                [("id", models.AutoField(primary_key=True))],
            ),
            ModelState(
                "testapp",
                "Magazine",
                [("id", models.AutoField(primary_key=True))],
            ),
            ModelState(
                "testapp",
                "Author",
                [
                    ("id", models.AutoField(primary_key=True)),
                    ("readings", models.ManyToManyField("testapp.Magazine")),
                ],
            ),
        ]
        changes = self.get_changes(before, after)
        self.assertNumberMigrations(changes, "testapp", 1)
        self.assertOperationTypes(changes, "testapp", 0, ["RemoveField", "AddField"])
        self.assertOperationAttributes(

Review comment (security):
I've just discovered these model states or similar are predefined, e.g. `self.author_with_m2m`. Can you switch to those here and, where appropriate, in `after` as well.

Code after:
            changes,
            "app",
            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,
        )