Loading django/db/migrations/operations/fields.py +10 −12 Original line number Diff line number Diff line Loading @@ -15,14 +15,13 @@ class AddField(Operation): state.models[app_label, self.model_name.lower()].fields.append((self.name, self.instance)) def database_forwards(self, app_label, schema_editor, from_state, to_state): app_cache = to_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.add_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) to_model = to_state.render().get_model(app_label, self.model_name) schema_editor.add_field(from_model, to_model._meta.get_field_by_name(self.name)[0]) def database_backwards(self, app_label, schema_editor, from_state, to_state): app_cache = from_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.remove_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0]) class RemoveField(Operation): Loading @@ -42,11 +41,10 @@ class RemoveField(Operation): state.models[app_label, self.model_name.lower()].fields = new_fields def database_forwards(self, app_label, schema_editor, from_state, to_state): app_cache = from_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.remove_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0]) def database_backwards(self, app_label, schema_editor, from_state, to_state): app_cache = to_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.add_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) to_model = to_state.render().get_model(app_label, self.model_name) schema_editor.add_field(from_model, to_model._meta.get_field_by_name(self.name)[0]) Loading
django/db/migrations/operations/fields.py +10 −12 Original line number Diff line number Diff line Loading @@ -15,14 +15,13 @@ class AddField(Operation): state.models[app_label, self.model_name.lower()].fields.append((self.name, self.instance)) def database_forwards(self, app_label, schema_editor, from_state, to_state): app_cache = to_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.add_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) to_model = to_state.render().get_model(app_label, self.model_name) schema_editor.add_field(from_model, to_model._meta.get_field_by_name(self.name)[0]) def database_backwards(self, app_label, schema_editor, from_state, to_state): app_cache = from_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.remove_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0]) class RemoveField(Operation): Loading @@ -42,11 +41,10 @@ class RemoveField(Operation): state.models[app_label, self.model_name.lower()].fields = new_fields def database_forwards(self, app_label, schema_editor, from_state, to_state): app_cache = from_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.remove_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) schema_editor.remove_field(from_model, from_model._meta.get_field_by_name(self.name)[0]) def database_backwards(self, app_label, schema_editor, from_state, to_state): app_cache = to_state.render() model = app_cache.get_model(app_label, self.model_name) schema_editor.add_field(model, model._meta.get_field_by_name(self.name)[0]) from_model = from_state.render().get_model(app_label, self.model_name) to_model = to_state.render().get_model(app_label, self.model_name) schema_editor.add_field(from_model, to_model._meta.get_field_by_name(self.name)[0])