(self)
| 2077 | self.assertEqual(counts, {"fks": expected_fks, "uniques": 0, "indexes": 1}) |
| 2078 | |
| 2079 | def test_alter_field_o2o_keeps_unique(self): |
| 2080 | with connection.schema_editor() as editor: |
| 2081 | editor.create_model(Author) |
| 2082 | editor.create_model(BookWithO2O) |
| 2083 | expected_fks = ( |
| 2084 | 1 |
| 2085 | if connection.features.supports_foreign_keys |
| 2086 | and connection.features.can_introspect_foreign_keys |
| 2087 | else 0 |
| 2088 | ) |
| 2089 | |
| 2090 | # Check the unique constraint is right to begin with. |
| 2091 | counts = self.get_constraints_count( |
| 2092 | BookWithO2O._meta.db_table, |
| 2093 | BookWithO2O._meta.get_field("author").column, |
| 2094 | (Author._meta.db_table, Author._meta.pk.column), |
| 2095 | ) |
| 2096 | self.assertEqual(counts, {"fks": expected_fks, "uniques": 1, "indexes": 0}) |
| 2097 | |
| 2098 | old_field = BookWithO2O._meta.get_field("author") |
| 2099 | # on_delete changed from CASCADE. |
| 2100 | new_field = OneToOneField(Author, PROTECT) |
| 2101 | new_field.set_attributes_from_name("author") |
| 2102 | with connection.schema_editor() as editor: |
| 2103 | editor.alter_field(BookWithO2O, old_field, new_field, strict=True) |
| 2104 | |
| 2105 | counts = self.get_constraints_count( |
| 2106 | BookWithO2O._meta.db_table, |
| 2107 | BookWithO2O._meta.get_field("author").column, |
| 2108 | (Author._meta.db_table, Author._meta.pk.column), |
| 2109 | ) |
| 2110 | # The unique constraint remains. |
| 2111 | self.assertEqual(counts, {"fks": expected_fks, "uniques": 1, "indexes": 0}) |
| 2112 | |
| 2113 | @skipUnlessDBFeature("ignores_table_name_case") |
| 2114 | def test_alter_db_table_case(self): |
nothing calls this directly
no test coverage detected