Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
--health-retries 5

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -55,7 +55,7 @@ jobs:
echo "::set-output name=dir::$(pip cache dir)"

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.2.1
=====

:release-date: not-released

- Avoid unnecessary prompting for a default value on `ManyToManyField`
removals. (#59)

1.2.0
=====

Expand Down
11 changes: 8 additions & 3 deletions syzygy/autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,14 @@ def _generate_added_field(self, app_label, model_name, field_name):
def _generate_removed_field(self, app_label, model_name, field_name):
field = self.from_state.models[app_label, model_name].fields[field_name]
remove_default = field.default
if (remove_default is NOT_PROVIDED and field.null) or getattr(
field, "db_default", NOT_PROVIDED
) is not NOT_PROVIDED:
if (
# Nullable fields will use null if not specified.
(remove_default is NOT_PROVIDED and field.null)
# Fields with a db_default will use the value if not specified.
or getattr(field, "db_default", NOT_PROVIDED) is not NOT_PROVIDED
# Many-to-many fields are not backend by concrete columns.
or field.many_to_many
):
return super()._generate_removed_field(app_label, model_name, field_name)

if remove_default is NOT_PROVIDED:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ def test_field_removal(self):
with self.subTest(field=field):
self._test_field_removal(field)

def test_many_to_many_removal(self):
from_model = ModelState(
"tests", "Model", [("field", models.ManyToManyField("self"))]
)
to_model = ModelState("tests", "Model", [])
changes = self.get_changes([from_model], [to_model])["tests"]
self.assertEqual(len(changes), 1)
self.assertEqual(get_migration_stage(changes[0]), Stage.POST_DEPLOY)
self.assertEqual(changes[0].dependencies, [])
self.assertEqual(len(changes[0].operations), 1)
operation = changes[0].operations[0]
self.assertIsInstance(operation, migrations.RemoveField)

def test_nullable_field_removal(self):
"""
No action required if the field is already NULL'able and doesn't have
Expand Down
Loading