MCPcopy
hub / github.com/django/django / test_add_auto_field

Method test_add_auto_field

tests/schema/tests.py:1064–1086  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1062
1063 @isolate_apps("schema")
1064 def test_add_auto_field(self):
1065 class AddAutoFieldModel(Model):
1066 name = CharField(max_length=255, primary_key=True)
1067
1068 class Meta:
1069 app_label = "schema"
1070
1071 with connection.schema_editor() as editor:
1072 editor.create_model(AddAutoFieldModel)
1073 self.isolated_local_models = [AddAutoFieldModel]
1074 old_field = AddAutoFieldModel._meta.get_field("name")
1075 new_field = CharField(max_length=255)
1076 new_field.set_attributes_from_name("name")
1077 new_field.model = AddAutoFieldModel
1078 with connection.schema_editor() as editor:
1079 editor.alter_field(AddAutoFieldModel, old_field, new_field)
1080 new_auto_field = AutoField(primary_key=True)
1081 new_auto_field.set_attributes_from_name("id")
1082 new_auto_field.model = AddAutoFieldModel()
1083 with connection.schema_editor() as editor:
1084 editor.add_field(AddAutoFieldModel, new_auto_field)
1085 # Crashes on PostgreSQL when the GENERATED BY suffix is missing.
1086 AddAutoFieldModel.objects.create(name="test")
1087
1088 def test_remove_field(self):
1089 with connection.schema_editor() as editor:

Callers

nothing calls this directly

Calls 10

CharFieldClass · 0.90
AutoFieldClass · 0.90
AddAutoFieldModelClass · 0.85
schema_editorMethod · 0.80
create_modelMethod · 0.45
get_fieldMethod · 0.45
alter_fieldMethod · 0.45
add_fieldMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected