File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -103,14 +103,12 @@ class DatabaseFeatures(BaseDatabaseFeatures):
103103 "schema.tests.SchemaTests.test_text_field_with_db_index" ,
104104 # AlterField
105105 "schema.tests.SchemaTests.test_alter_field_add_index_to_integerfield" ,
106- "schema.tests.SchemaTests.test_alter_field_default_dropped" ,
107106 "schema.tests.SchemaTests.test_alter_field_fk_keeps_index" ,
108107 "schema.tests.SchemaTests.test_alter_field_fk_to_o2o" ,
109108 "schema.tests.SchemaTests.test_alter_field_o2o_keeps_unique" ,
110109 "schema.tests.SchemaTests.test_alter_field_o2o_to_fk" ,
111110 "schema.tests.SchemaTests.test_alter_int_pk_to_int_unique" ,
112111 "schema.tests.SchemaTests.test_alter_not_unique_field_to_primary_key" ,
113- "schema.tests.SchemaTests.test_alter_null_to_not_null" ,
114112 # AlterField (db_index)
115113 "schema.tests.SchemaTests.test_alter_renames_index" ,
116114 "schema.tests.SchemaTests.test_indexes" ,
Original file line number Diff line number Diff line change @@ -38,11 +38,16 @@ def _alter_field(
3838 new_db_params ,
3939 strict = False ,
4040 ):
41+ collection = self .connection .database [model ._meta .db_table ]
4142 # Have they renamed the column?
4243 if old_field .column != new_field .column :
43- self .connection .database [model ._meta .db_table ].update_many (
44- {}, {"$rename" : {old_field .column : new_field .column }}
45- )
44+ collection .update_many ({}, {"$rename" : {old_field .column : new_field .column }})
45+ # Replace NULL with the field default if the field and was changed from
46+ # NULL to NOT NULL.
47+ if new_field .has_default () and old_field .null and not new_field .null :
48+ column = new_field .column
49+ default = self .effective_default (new_field )
50+ collection .update_many ({column : {"$eq" : None }}, [{"$set" : {column : default }}])
4651
4752 def remove_field (self , model , field ):
4853 # Remove implicit M2M tables.
You can’t perform that action at this time.
0 commit comments