From 7ca42974ee087a82b6f7f6874ca2b25e42a9a584 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 24 Aug 2020 00:45:48 -0400 Subject: [PATCH] Added assertions for the results of migrating an integer pk to AutoField. --- tests/schema/tests.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/schema/tests.py b/tests/schema/tests.py index d31a12e504..e516b17b59 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -1346,6 +1346,20 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_field(IntegerPK, old_field, new_field, strict=True) + # A model representing the updated model. + class IntegerPKToAutoField(Model): + i = AutoField(primary_key=True) + j = IntegerField(unique=True) + + class Meta: + app_label = 'schema' + apps = new_apps + db_table = IntegerPK._meta.db_table + + # An id (i) is generated by the database. + obj = IntegerPKToAutoField.objects.create(j=1) + self.assertIsNotNone(obj.i) + def test_alter_int_pk_to_bigautofield_pk(self): """ Should be able to rename an IntegerField(primary_key=True) to @@ -1362,6 +1376,20 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_field(IntegerPK, old_field, new_field, strict=True) + # A model representing the updated model. + class IntegerPKToBigAutoField(Model): + i = BigAutoField(primary_key=True) + j = IntegerField(unique=True) + + class Meta: + app_label = 'schema' + apps = new_apps + db_table = IntegerPK._meta.db_table + + # An id (i) is generated by the database. + obj = IntegerPKToBigAutoField.objects.create(j=1) + self.assertIsNotNone(obj.i) + @isolate_apps('schema') def test_alter_smallint_pk_to_smallautofield_pk(self): """