(self)
| 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: |
nothing calls this directly
no test coverage detected