| 233 | ) |
| 234 | |
| 235 | def database_forwards(self, app_label, schema_editor, from_state, to_state): |
| 236 | to_model = to_state.apps.get_model(app_label, self.model_name) |
| 237 | if self.allow_migrate_model(schema_editor.connection.alias, to_model): |
| 238 | from_model = from_state.apps.get_model(app_label, self.model_name) |
| 239 | from_field = from_model._meta.get_field(self.name) |
| 240 | to_field = to_model._meta.get_field(self.name) |
| 241 | if not self.preserve_default: |
| 242 | to_field.default = self.field.default |
| 243 | schema_editor.alter_field(from_model, from_field, to_field) |
| 244 | if not self.preserve_default: |
| 245 | to_field.default = NOT_PROVIDED |
| 246 | |
| 247 | def database_backwards(self, app_label, schema_editor, from_state, to_state): |
| 248 | self.database_forwards(app_label, schema_editor, from_state, to_state) |