Commit cca40703 authored by Andrew Godwin's avatar Andrew Godwin
Browse files

Prompt about renames rather than doing them automatically

parent 92a10f55
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -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(
@@ -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):

@@ -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__))
+1 −1
Original line number Diff line number Diff line
@@ -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)