summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
authorBen Cail <bcail@crossway.org>2024-10-02 17:05:33 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-02-06 13:53:43 +0100
commitdb7b1ae9f6d9e26facbb3da4cf5f5a513704bfe5 (patch)
treee4885dbe69bc89f0af5087ed35494a2f3bc6e663 /tests/migrations
parent1f33f21fca60c3839bcfc756900fb78bcfd15cc3 (diff)
Refs #22997 -- Prevented requesting a default value for auto fields.
Diffstat (limited to 'tests/migrations')
-rw-r--r--tests/migrations/test_autodetector.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 33196ea6f4..ac725d317e 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1596,6 +1596,34 @@ class AutodetectorTests(BaseAutodetectorTests):
)
@mock.patch(
+ "django.db.migrations.questioner.MigrationQuestioner.ask_not_null_addition"
+ )
+ def test_add_auto_field_does_not_request_default(self, mocked_ask_method):
+ initial_state = ModelState(
+ "testapp",
+ "Author",
+ [
+ ("pkfield", models.IntegerField(primary_key=True)),
+ ],
+ )
+ for auto_field in [
+ models.AutoField,
+ models.BigAutoField,
+ models.SmallAutoField,
+ ]:
+ with self.subTest(auto_field=auto_field):
+ updated_state = ModelState(
+ "testapp",
+ "Author",
+ [
+ ("id", auto_field(primary_key=True)),
+ ("pkfield", models.IntegerField(primary_key=False)),
+ ],
+ )
+ self.get_changes([initial_state], [updated_state])
+ mocked_ask_method.assert_not_called()
+
+ @mock.patch(
"django.db.migrations.questioner.MigrationQuestioner.ask_not_null_alteration",
return_value=models.NOT_PROVIDED,
)