Repository: django/django

Issue:
# Fixed #36639 -- Added CI step to run makemigrations --check against test models.

#### Trac ticket number
<!-- Replace XXXXX with the corresponding Trac ticket number, or delete the line and write "N/A" if this is a trivial PR. -->

ticket-36639

#### Branch description
This PR automated migration consistency checks for the test models with current migrations and added missing migration files . 
I have tested this PR on my local with "act" package.

SS before fixing  migrations: 
<img width="1600" height="633" alt="image" src="https://github.com/user-attachments/assets/1298c395-2262-439a-8c4d-a034840beb50" />

SS after fixing migrations:
<img width="1600" height="376" alt="image" src="https://github.com/user-attachments/assets/f4d14ce1-d4ab-4727-803d-4a288c67c595" />


#### Checklist
- [x] This PR targets the `main` branch. <!-- Backports will be evaluated and done by mergers, when necessary. -->
- [x] The commit message is written in past tense, mentions the ticket number, and ends with a period.
- [x] I have checked the "Has patch" ticket flag in the Trac system.
- [ ] I have added or updated relevant tests.
- [ ] I have added or updated relevant docs, including release notes if applicable.
- [ ] I have attached screenshots in both light and dark modes for any UI changes.


Implementation patch:
diff --git a/scripts/check_migrations.py b/scripts/check_migrations.py
new file mode 100644
index 000000000000..70d187e14433
--- /dev/null
+++ b/scripts/check_migrations.py
@@ -0,0 +1,31 @@
+import sys
+from pathlib import Path
+
+
+def main():
+    repo_root = Path(__file__).resolve().parent.parent
+    sys.path[:0] = [str(repo_root / "tests"), str(repo_root)]
+
+    from runtests import ALWAYS_INSTALLED_APPS, get_apps_to_install, get_test_modules
+
+    import django
+    from django.apps import apps
+    from django.core.management import call_command
+
+    django.setup()
+
+    test_modules = list(get_test_modules(gis_enabled=False))
+    installed_apps = list(ALWAYS_INSTALLED_APPS)
+    for app in get_apps_to_install(test_modules):
+        # Check against the list to prevent duplicate errors.
+        if app not in installed_apps:
+            installed_apps.append(app)
+    apps.set_installed_apps(installed_apps)
+
+    # Note: We don't use check=True here because --check calls sys.exit(1)
+    # instead of raising CommandError when migrations are missing.
+    call_command("makemigrations", "--check", verbosity=3)
+
+
+if __name__ == "__main__":
+    main()


Test patch:
diff --git a/tests/db_functions/migrations/0002_create_test_models.py b/tests/db_functions/migrations/0002_create_test_models.py
index 6c4626e7ea44..2fa924cbe005 100644
--- a/tests/db_functions/migrations/0002_create_test_models.py
+++ b/tests/db_functions/migrations/0002_create_test_models.py
@@ -10,6 +10,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="Author",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("name", models.CharField(max_length=50)),
                 ("alias", models.CharField(max_length=50, null=True, blank=True)),
                 ("goes_by", models.CharField(max_length=50, null=True, blank=True)),
@@ -19,6 +28,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="Article",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 (
                     "authors",
                     models.ManyToManyField(
@@ -37,6 +55,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="Fan",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("name", models.CharField(max_length=50)),
                 ("age", models.PositiveSmallIntegerField(default=30)),
                 (
@@ -51,6 +78,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="DTModel",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("name", models.CharField(max_length=32)),
                 ("start_datetime", models.DateTimeField(null=True, blank=True)),
                 ("end_datetime", models.DateTimeField(null=True, blank=True)),
@@ -64,6 +100,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="DecimalModel",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("n1", models.DecimalField(decimal_places=2, max_digits=6)),
                 (
                     "n2",
@@ -76,6 +121,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="IntegerModel",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("big", models.BigIntegerField(null=True, blank=True)),
                 ("normal", models.IntegerField(null=True, blank=True)),
                 ("small", models.SmallIntegerField(null=True, blank=True)),
@@ -84,6 +138,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="FloatModel",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("f1", models.FloatField(null=True, blank=True)),
                 ("f2", models.FloatField(null=True, blank=True)),
             ],
@@ -91,6 +154,15 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name="UUIDModel",
             fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
                 ("uuid", models.UUIDField(null=True)),
                 ("shift", models.DurationField(null=True)),
             ],
diff --git a/tests/gis_tests/rasterapp/migrations/0002_rastermodels.py b/tests/gis_tests/rasterapp/migrations/0002_rastermodels.py
index bd2a72ab45ad..c47cd044c82a 100644
--- a/tests/gis_tests/rasterapp/migrations/0002_rastermodels.py
+++ b/tests/gis_tests/rasterapp/migrations/0002_rastermodels.py
@@ -14,7 +14,7 @@ class Migration(migrations.Migration):
             fields=[
                 (
                     "id",
-                    models.AutoField(
+                    models.BigAutoField(
                         auto_created=True,
                         primary_key=True,
                         serialize=False,
@@ -49,7 +49,7 @@ class Migration(migrations.Migration):
             fields=[
                 (
                     "id",
-                    models.AutoField(
+                    models.BigAutoField(
                         auto_created=True,
                         primary_key=True,
                         serialize=False,
diff --git a/tests/migration_test_data_persistence/migrations/0002_add_book.py b/tests/migration_test_data_persistence/migrations/0002_add_book.py
index c355428f34bc..325ac6668452 100644
--- a/tests/migration_test_data_persistence/migrations/0002_add_book.py
+++ b/tests/migration_test_data_persistence/migrations/0002_add_book.py
@@ -1,4 +1,4 @@
-from django.db import migrations
+from django.db import migrations, models
 
 
 def add_book(apps, schema_editor):
@@ -16,4 +16,29 @@ class Migration(migrations.Migration):
         migrations.RunPython(
             add_book,
         ),
+        migrations.CreateModel(
+            name="Unmanaged",
+            fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+                ("title", models.CharField(max_length=100)),
+            ],
+            options={
+                "managed": False,
+            },
+        ),
+        migrations.AlterField(
+            model_name="book",
+            name="id",
+            field=models.BigAutoField(
+                auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
+            ),
+        ),
     ]
diff --git a/tests/postgres_tests/migrations/0002_create_test_models.py b/tests/postgres_tests/migrations/0002_create_test_models.py
index d2f9eceb9931..9e1831b5e901 100644
--- a/tests/postgres_tests/migrations/0002_create_test_models.py
+++ b/tests/postgres_tests/migrations/0002_create_test_models.py
@@ -108,7 +108,7 @@ class Migration(migrations.Migration):
                 ("tags", ArrayField(TagField(), blank=True, null=True)),
                 (
                     "json",
-                    ArrayField(models.JSONField(default=dict), default=list),
+                    ArrayField(models.JSONField(default=dict), default=list, null=True),
                 ),
                 ("int_ranges", ArrayField(IntegerRangeField(), null=True, blank=True)),
                 (
@@ -179,7 +179,7 @@ class Migration(migrations.Migration):
                 ),
                 (
                     "field",
-                    ArrayField(models.FloatField(), size=2, null=True, blank=True),
+                    ArrayField(models.FloatField(), size=3),
                 ),
             ],
             options={
diff --git a/tests/sites_framework/migrations/0001_initial.py b/tests/sites_framework/migrations/0001_initial.py
index c5721ee08e38..dbd491027639 100644
--- a/tests/sites_framework/migrations/0001_initial.py
+++ b/tests/sites_framework/migrations/0001_initial.py
@@ -1,3 +1,5 @@
+import django.contrib.sites.managers
+import django.db.models.manager
 from django.db import migrations, models
 
 
@@ -12,11 +14,11 @@ class Migration(migrations.Migration):
             fields=[
                 (
                     "id",
-                    models.AutoField(
-                        verbose_name="ID",
-                        serialize=False,
+                    models.BigAutoField(
                         auto_created=True,
                         primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
                     ),
                 ),
                 ("title", models.CharField(max_length=50)),
@@ -28,6 +30,15 @@ class Migration(migrations.Migration):
             options={
                 "abstract": False,
             },
+            managers=[
+                ("objects", django.db.models.manager.Manager()),
+                (
+                    "on_site",
+                    django.contrib.sites.managers.CurrentSiteManager(
+                        "places_this_article_should_appear"
+                    ),
+                ),
+            ],
             bases=(models.Model,),
         ),
         migrations.CreateModel(
@@ -35,11 +46,11 @@ class Migration(migrations.Migration):
             fields=[
                 (
                     "id",
-                    models.AutoField(
-                        verbose_name="ID",
-                        serialize=False,
+                    models.BigAutoField(
                         auto_created=True,
                         primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
                     ),
                 ),
                 ("title", models.CharField(max_length=50)),
@@ -48,6 +59,10 @@ class Migration(migrations.Migration):
             options={
                 "abstract": False,
             },
+            managers=[
+                ("objects", django.db.models.manager.Manager()),
+                ("on_site", django.contrib.sites.managers.CurrentSiteManager()),
+            ],
             bases=(models.Model,),
         ),
         migrations.CreateModel(
@@ -55,11 +70,11 @@ class Migration(migrations.Migration):
             fields=[
                 (
                     "id",
-                    models.AutoField(
-                        verbose_name="ID",
-                        serialize=False,
+                    models.BigAutoField(
                         auto_created=True,
                         primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
                     ),
                 ),
                 ("title", models.CharField(max_length=50)),
@@ -68,6 +83,10 @@ class Migration(migrations.Migration):
             options={
                 "abstract": False,
             },
+            managers=[
+                ("objects", django.db.models.manager.Manager()),
+                ("on_site", django.contrib.sites.managers.CurrentSiteManager()),
+            ],
             bases=(models.Model,),
         ),
     ]