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):
103
103
"schema.tests.SchemaTests.test_text_field_with_db_index" ,
104
104
# AlterField
105
105
"schema.tests.SchemaTests.test_alter_field_add_index_to_integerfield" ,
106
- "schema.tests.SchemaTests.test_alter_field_default_dropped" ,
107
106
"schema.tests.SchemaTests.test_alter_field_fk_keeps_index" ,
108
107
"schema.tests.SchemaTests.test_alter_field_fk_to_o2o" ,
109
108
"schema.tests.SchemaTests.test_alter_field_o2o_keeps_unique" ,
110
109
"schema.tests.SchemaTests.test_alter_field_o2o_to_fk" ,
111
110
"schema.tests.SchemaTests.test_alter_int_pk_to_int_unique" ,
112
111
"schema.tests.SchemaTests.test_alter_not_unique_field_to_primary_key" ,
113
- "schema.tests.SchemaTests.test_alter_null_to_not_null" ,
114
112
# AlterField (db_index)
115
113
"schema.tests.SchemaTests.test_alter_renames_index" ,
116
114
"schema.tests.SchemaTests.test_indexes" ,
Original file line number Diff line number Diff line change @@ -38,11 +38,16 @@ def _alter_field(
38
38
new_db_params ,
39
39
strict = False ,
40
40
):
41
+ collection = self .connection .database [model ._meta .db_table ]
41
42
# Have they renamed the column?
42
43
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 }}])
46
51
47
52
def remove_field (self , model , field ):
48
53
# Remove implicit M2M tables.
You can’t perform that action at this time.
0 commit comments