mirror of
https://github.com/django/django.git
synced 2025-01-08 17:37:20 +00:00
Added assertions for the results of migrating an integer pk to AutoField.
This commit is contained in:
parent
3e753d3de3
commit
7ca42974ee
@ -1346,6 +1346,20 @@ class SchemaTests(TransactionTestCase):
|
|||||||
with connection.schema_editor() as editor:
|
with connection.schema_editor() as editor:
|
||||||
editor.alter_field(IntegerPK, old_field, new_field, strict=True)
|
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):
|
def test_alter_int_pk_to_bigautofield_pk(self):
|
||||||
"""
|
"""
|
||||||
Should be able to rename an IntegerField(primary_key=True) to
|
Should be able to rename an IntegerField(primary_key=True) to
|
||||||
@ -1362,6 +1376,20 @@ class SchemaTests(TransactionTestCase):
|
|||||||
with connection.schema_editor() as editor:
|
with connection.schema_editor() as editor:
|
||||||
editor.alter_field(IntegerPK, old_field, new_field, strict=True)
|
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')
|
@isolate_apps('schema')
|
||||||
def test_alter_smallint_pk_to_smallautofield_pk(self):
|
def test_alter_smallint_pk_to_smallautofield_pk(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user