diff --git tests/migrations/test_operations.py tests/migrations/test_operations.py
index c8f1189..b252424 100644
--- tests/migrations/test_operations.py
+++ tests/migrations/test_operations.py
@@ -1850,6 +1850,90 @@ class OperationTests(OperationTestBase):
         self.assertEqual(definition[1], [])
         self.assertEqual(sorted(definition[2]), ["database_operations", "state_operations"])
 
+    def test_m2m_intermediate_table_is_not_migrated_properly(self):
+        """
+        Primary key changes are not reflected in m2m intermediate table
+        """
+        def initial_data(models, schema_editor):
+            Article = models.get_model("test_m2m", "Article")
+            Tag = models.get_model("test_m2m", "Tag")
+            tag1 = Tag.objects.create(name='framework')
+            tag2 = Tag.objects.create(name='web')
+            article = Article.objects.create(name="Frameworks", data="Hello World", id='a' * 5)
+            article.tag.add(tag1, tag2)
+
+        def big_data(models, schema_editor):
+            Article = models.get_model("test_m2m", "Article")
+            Tag = models.get_model("test_m2m", "Tag")
+            tag1 = Tag.objects.create(name='data')
+            article = Article.objects.create(name="Frameworks", data="Hello World", id='b' * 20)
+            article.tag.add(tag1)
+
+        create_tag = migrations.CreateModel(
+            "Tag",
+            [
+                ("name", models.CharField(max_length=50)),
+            ],
+            options={},
+        )
+
+        create_article = migrations.CreateModel(
+            "Article",
+            [
+                ("id", models.CharField(primary_key=True, max_length=10)),
+                ("name", models.CharField(max_length=100)),
+                ("data", models.TextField(default="")),
+                ("tag", models.ManyToManyField(to="test_m2m.Tag")),
+            ],
+            options={},
+        )
+
+        fill_initial_data = migrations.RunPython(initial_data, initial_data)
+
+        def grow_article_id(new_state):
+            _grow_article_id = migrations.AlterField(
+                "Article",
+                "id",
+                models.CharField(primary_key=True, max_length=50)
+            )
+            project_state = new_state
+            new_state = new_state.clone()
+            with connection.schema_editor() as editor:
+                _grow_article_id.state_forwards("test_m2m", new_state)
+                _grow_article_id.database_forwards("test_m2m", editor, project_state, new_state)
+            return new_state
+
+        def fill_big_data(new_state):
+            project_state = new_state
+            new_state = new_state.clone()
+            _fill_big_data = migrations.RunPython(big_data, big_data)
+            with connection.schema_editor() as editor:
+                _fill_big_data.state_forwards("fill_big_data", new_state)
+                _fill_big_data.database_forwards("fill_big_data", editor, project_state, new_state)
+            return new_state
+
+        project_state = ProjectState()
+        new_state = project_state.clone()
+        with connection.schema_editor() as editor:
+            create_tag.state_forwards("test_m2m", new_state)
+            create_tag.database_forwards("test_m2m", editor, project_state, new_state)
+
+        project_state = new_state
+        new_state = new_state.clone()
+        with connection.schema_editor() as editor:
+            create_article.state_forwards("test_m2m", new_state)
+            create_article.database_forwards("test_m2m", editor, project_state, new_state)
+
+        project_state = new_state
+        new_state = new_state.clone()
+        with connection.schema_editor() as editor:
+            fill_initial_data.state_forwards("fill_initial_data", new_state)
+            fill_initial_data.database_forwards("fill_initial_data", editor, project_state, new_state)
+
+        new_state = grow_article_id(new_state)
+
+        fill_big_data(new_state)  # no exception for sqlite, IntegrityError or DataError for other backends
+
 
 class SwappableOperationTests(OperationTestBase):
     """
