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 @@ -100,14 +100,12 @@ class DatabaseFeatures(BaseDatabaseFeatures):
100
100
# AlterField
101
101
"schema.tests.SchemaTests.test_alter_auto_field_to_integer_field" ,
102
102
"schema.tests.SchemaTests.test_alter_field_add_index_to_integerfield" ,
103
- "schema.tests.SchemaTests.test_alter_field_default_dropped" ,
104
103
"schema.tests.SchemaTests.test_alter_field_fk_keeps_index" ,
105
104
"schema.tests.SchemaTests.test_alter_field_fk_to_o2o" ,
106
105
"schema.tests.SchemaTests.test_alter_field_o2o_keeps_unique" ,
107
106
"schema.tests.SchemaTests.test_alter_field_o2o_to_fk" ,
108
107
"schema.tests.SchemaTests.test_alter_int_pk_to_int_unique" ,
109
108
"schema.tests.SchemaTests.test_alter_not_unique_field_to_primary_key" ,
110
- "schema.tests.SchemaTests.test_alter_null_to_not_null" ,
111
109
"schema.tests.SchemaTests.test_alter_primary_key_the_same_name" ,
112
110
"schema.tests.SchemaTests.test_autofield_to_o2o" ,
113
111
# AlterField (db_index)
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