1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Added assertions for the results of migrating an integer pk to AutoField.

This commit is contained in:
Tim Graham 2020-08-24 00:45:48 -04:00 committed by GitHub
parent 3e753d3de3
commit 7ca42974ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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):
"""