Loading django/db/migrations/autodetector.py +20 −11 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ class MigrationAutodetector(object): found_rename = False for removed_field_name in (old_field_names - new_field_names): if old_model_state.get_field_by_name(removed_field_name).deconstruct()[1:] == field_dec: if self.questioner.ask_rename(model_name, removed_field_name, field_name, field): self.add_to_migration( app_label, operations.RenameField( Loading Loading @@ -257,6 +258,10 @@ class MigrationQuestioner(object): # None means quit return None def ask_rename(self, model_name, old_name, new_name, field_instance): "Was this field really renamed?" return self.defaults.get("ask_rename", False) class InteractiveMigrationQuestioner(MigrationQuestioner): Loading Loading @@ -323,3 +328,7 @@ class InteractiveMigrationQuestioner(MigrationQuestioner): print("Invalid input: %s" % e) else: break def ask_rename(self, model_name, old_name, new_name, field_instance): "Was this field really renamed?" return self._boolean_input("Did you rename %s.%s to %s.%s (a %s)?" % (model_name, old_name, model_name, new_name, field_instance.__class__.__name__)) tests/migrations/test_autodetector.py +1 −1 Original line number Diff line number Diff line Loading @@ -155,7 +155,7 @@ class AutodetectorTests(TestCase): # Make state before = self.make_project_state([self.author_name]) after = self.make_project_state([self.author_name_renamed]) autodetector = MigrationAutodetector(before, after) autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_rename": True})) changes = autodetector.changes() # Right number of migrations? self.assertEqual(len(changes['testapp']), 1) Loading Loading
django/db/migrations/autodetector.py +20 −11 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ class MigrationAutodetector(object): found_rename = False for removed_field_name in (old_field_names - new_field_names): if old_model_state.get_field_by_name(removed_field_name).deconstruct()[1:] == field_dec: if self.questioner.ask_rename(model_name, removed_field_name, field_name, field): self.add_to_migration( app_label, operations.RenameField( Loading Loading @@ -257,6 +258,10 @@ class MigrationQuestioner(object): # None means quit return None def ask_rename(self, model_name, old_name, new_name, field_instance): "Was this field really renamed?" return self.defaults.get("ask_rename", False) class InteractiveMigrationQuestioner(MigrationQuestioner): Loading Loading @@ -323,3 +328,7 @@ class InteractiveMigrationQuestioner(MigrationQuestioner): print("Invalid input: %s" % e) else: break def ask_rename(self, model_name, old_name, new_name, field_instance): "Was this field really renamed?" return self._boolean_input("Did you rename %s.%s to %s.%s (a %s)?" % (model_name, old_name, model_name, new_name, field_instance.__class__.__name__))
tests/migrations/test_autodetector.py +1 −1 Original line number Diff line number Diff line Loading @@ -155,7 +155,7 @@ class AutodetectorTests(TestCase): # Make state before = self.make_project_state([self.author_name]) after = self.make_project_state([self.author_name_renamed]) autodetector = MigrationAutodetector(before, after) autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_rename": True})) changes = autodetector.changes() # Right number of migrations? self.assertEqual(len(changes['testapp']), 1) Loading