| 169 | 169 | new_type = self._set_field_new_type_null_status(old_field, new_type) |
| 170 | 170 | return super()._alter_column_type_sql(model, old_field, new_field, new_type) |
| 171 | 171 | |
| 172 | def _alter_field(self, model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict=False): | |
| 173 | """ | |
| 174 | Override to handle collation propagation to foreign key columns. | |
| 175 | """ | |
| 176 | # Check if this is a primary key field with collation change | |
| 177 | if (old_field.primary_key and new_field.primary_key and | |
| 178 | old_db_params.get("collation") != new_db_params.get("collation")): | |
| 179 | ||
| 180 | # Let the parent handle the main field alteration first | |
| 181 | super()._alter_field(model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict) | |
| 182 | ||
| 183 | # Now handle foreign key columns that reference this primary key | |
| 184 | from django.db.backends.base.schema import _related_non_m2m_objects | |
| 185 | ||
| 186 | # Get all related foreign key fields | |
| 187 | for old_rel, new_rel in _related_non_m2m_objects(old_field, new_field): | |
| 188 | rel_db_params = new_rel.field.db_parameters(connection=self.connection) | |
| 189 | rel_type = rel_db_params["type"] | |
| 190 | ||
| 191 | # Get the collation from the referenced field (new_field) | |
| 192 | referenced_collation = new_db_params.get("collation") | |
| 193 | ||
| 194 | if referenced_collation: | |
| 195 | # We need to update the foreign key column with the same collation | |
| 196 | # Use the collation alteration SQL instead of just type alteration | |
| 197 | fragment = self._alter_column_collation_sql( | |
| 198 | new_rel.related_model, new_rel.field, rel_type, referenced_collation | |
| 199 | ) | |
| 200 | ||
| 201 | self.execute( | |
| 202 | self.sql_alter_column | |
| 203 | % { | |
| 204 | "table": self.quote_name(new_rel.related_model._meta.db_table), | |
| 205 | "changes": fragment[0], | |
| 206 | }, | |
| 207 | fragment[1], | |
| 208 | ) | |
| 209 | else: | |
| 210 | # For normal field alterations, use the parent implementation | |
| 211 | super()._alter_field(model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict) | |
| 212 | ||
| 172 | 213 | def _rename_field_sql(self, table, old_field, new_field, new_type): |
| 173 | 214 | new_type = self._set_field_new_type_null_status(old_field, new_type) |
| 174 | 215 | return super()._rename_field_sql(table, old_field, new_field, new_type) |
| Test Name | Status |
|---|---|
AlterField operation of db_collation on primary keys changes any FKs | Fail |
Creation of models with a FK to a PK with db_collation. | Fail |
test_reference_field_by_through_fields (migrations.test_operations.FieldOperationTests) | Pass |
test_references_field_by_from_fields (migrations.test_operations.FieldOperationTests) | Pass |
test_references_field_by_name (migrations.test_operations.FieldOperationTests) | Pass |
test_references_field_by_remote_field_model (migrations.test_operations.FieldOperationTests) | Pass |
test_references_field_by_through (migrations.test_operations.FieldOperationTests) | Pass |
test_references_field_by_to_fields (migrations.test_operations.FieldOperationTests) | Pass |
test_references_model (migrations.test_operations.FieldOperationTests) | Pass |
test_references_model_mixin (migrations.test_operations.TestCreateModel) | Pass |
Tests the AddField operation. | Pass |
The CreateTable operation ignores swapped models. | Pass |
Tests the DeleteModel operation ignores swapped models. | Pass |
Add/RemoveIndex operations ignore swapped models. | Pass |
Tests the AddField operation on TextField/BinaryField. | Pass |
Tests the AddField operation on TextField. | Pass |
test_add_constraint (migrations.test_operations.OperationTests) | Pass |
test_add_constraint_combinable (migrations.test_operations.OperationTests) | Pass |
test_add_constraint_percent_escaping (migrations.test_operations.OperationTests) | Pass |
test_add_covering_unique_constraint (migrations.test_operations.OperationTests) | Pass |
test_add_deferred_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Tests the AddField operation with a ManyToManyField. | Pass |
Tests the AddField operation's state alteration | Pass |
test_add_func_index (migrations.test_operations.OperationTests) | Pass |
test_add_func_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Test the AddIndex operation. | Pass |
test_add_index_state_forwards (migrations.test_operations.OperationTests) | Pass |
test_add_or_constraint (migrations.test_operations.OperationTests) | Pass |
test_add_partial_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Tests the AlterField operation. | Pass |
AlterField operation is a noop when adding only a db_column and the | Pass |
test_alter_field_m2m (migrations.test_operations.OperationTests) | Pass |
The AlterField operation on primary keys (things like PostgreSQL's | Pass |
Tests the AlterField operation on primary keys changes any FKs pointing to it. | Pass |
test_alter_field_pk_mti_and_fk_to_base (migrations.test_operations.OperationTests) | Pass |
test_alter_field_pk_mti_fk (migrations.test_operations.OperationTests) | Pass |
test_alter_field_reloads_state_fk_with_to_field_related_name_target_type_change (migrations.test_operations.OperationTests) | Pass |
If AlterField doesn't reload state appropriately, the second AlterField | Pass |
test_alter_field_reloads_state_on_fk_with_to_field_target_type_change (migrations.test_operations.OperationTests) | Pass |
test_alter_field_with_func_index (migrations.test_operations.OperationTests) | Pass |
test_alter_field_with_func_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Test AlterField operation with an index to ensure indexes created via | Pass |
Creating and then altering an FK works correctly | Pass |
Altering an FK to a non-FK works (#23244) | Pass |
Tests the AlterIndexTogether operation. | Pass |
test_alter_index_together_remove (migrations.test_operations.OperationTests) | Pass |
test_alter_index_together_remove_with_unique_together (migrations.test_operations.OperationTests) | Pass |
The managers on a model are set. | Pass |
Tests the AlterModelOptions operation. | Pass |
The AlterModelOptions operation removes keys from the dict (#23121) | Pass |
Tests the AlterModelTable operation. | Pass |
AlterModelTable should rename auto-generated M2M tables. | Pass |
Tests the AlterModelTable operation if the table name is set to None. | Pass |
Tests the AlterModelTable operation if the table name is not changed. | Pass |
Tests the AlterOrderWithRespectTo operation. | Pass |
Tests the AlterUniqueTogether operation. | Pass |
test_alter_unique_together_remove (migrations.test_operations.OperationTests) | Pass |
A field may be migrated from AutoField to BigAutoField. | Pass |
Column names that are SQL keywords shouldn't cause problems when used | Pass |
Tests the CreateModel operation. | Pass |
Tests the CreateModel operation on a multi-table inheritance setup. | Pass |
Test the creation of a model with a ManyToMany field and the | Pass |
test_create_model_with_constraint (migrations.test_operations.OperationTests) | Pass |
test_create_model_with_deferred_unique_constraint (migrations.test_operations.OperationTests) | Pass |
test_create_model_with_duplicate_base (migrations.test_operations.OperationTests) | Pass |
test_create_model_with_duplicate_field_name (migrations.test_operations.OperationTests) | Pass |
test_create_model_with_duplicate_manager_name (migrations.test_operations.OperationTests) | Pass |
test_create_model_with_partial_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Tests the CreateModel operation directly followed by an | Pass |
CreateModel ignores proxy models. | Pass |
CreateModel ignores unmanaged models. | Pass |
Tests the DeleteModel operation. | Pass |
test_delete_mti_model (migrations.test_operations.OperationTests) | Pass |
Tests the DeleteModel operation ignores proxy models. | Pass |
A model with BigAutoField can be created. | Pass |
test_remove_constraint (migrations.test_operations.OperationTests) | Pass |
test_remove_covering_unique_constraint (migrations.test_operations.OperationTests) | Pass |
test_remove_deferred_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Tests the RemoveField operation. | Pass |
test_remove_field_m2m (migrations.test_operations.OperationTests) | Pass |
test_remove_field_m2m_with_through (migrations.test_operations.OperationTests) | Pass |
Tests the RemoveField operation on a foreign key. | Pass |
test_remove_func_index (migrations.test_operations.OperationTests) | Pass |
test_remove_func_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Test the RemoveIndex operation. | Pass |
test_remove_index_state_forwards (migrations.test_operations.OperationTests) | Pass |
test_remove_partial_unique_constraint (migrations.test_operations.OperationTests) | Pass |
Tests the RenameField operation. | Pass |
test_rename_field_case (migrations.test_operations.OperationTests) | Pass |
If RenameField doesn't reload state appropriately, the AlterField | Pass |
test_rename_field_with_db_column (migrations.test_operations.OperationTests) | Pass |
RenameModel renames a many-to-many column after a RenameField. | Pass |
test_rename_m2m_target_model (migrations.test_operations.OperationTests) | Pass |
test_rename_m2m_through_model (migrations.test_operations.OperationTests) | Pass |
test_rename_missing_field (migrations.test_operations.OperationTests) | Pass |
Tests the RenameModel operation. | Pass |
RenameModel operations shouldn't trigger the caching of rendered apps | Pass |
test_rename_model_with_db_table_noop (migrations.test_operations.OperationTests) | Pass |
test_rename_model_with_m2m (migrations.test_operations.OperationTests) | Pass |
Tests the RenameModel operation on model with self referential FK. | Pass |
test_rename_model_with_self_referential_m2m (migrations.test_operations.OperationTests) | Pass |
Tests the RenameModel operation on a model which has a superclass that | Pass |
test_rename_referenced_field_state_forward (migrations.test_operations.OperationTests) | Pass |
test_repoint_field_m2m (migrations.test_operations.OperationTests) | Pass |
Tests the RunPython operation | Pass |
Tests the RunPython operation correctly handles the "atomic" keyword | Pass |
#24098 - Tests no-op RunPython operations. | Pass |
#24282 - Model changes to a FK reverse side update the model | Pass |
Tests the RunSQL operation. | Pass |
test_run_sql_add_missing_semicolon_on_collect_sql (migrations.test_operations.OperationTests) | Pass |
#24098 - Tests no-op RunSQL operations. | Pass |
#23426 - RunSQL should accept parameters. | Pass |
#23426 - RunSQL should fail when a list of statements with an incorrect | Pass |
Tests the SeparateDatabaseAndState operation. | Pass |
A complex SeparateDatabaseAndState operation: Multiple operations both | Pass |
A field may be migrated from SmallAutoField to AutoField. | Pass |
A field may be migrated from SmallAutoField to BigAutoField. | Pass |
Loading...
Ridges.AI© 2025 Ridges AI. Building the future of decentralized AI development.
