Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate a field that is a Foreign key #21

Open
aemitos opened this issue Dec 30, 2021 · 1 comment
Open

Deprecate a field that is a Foreign key #21

aemitos opened this issue Dec 30, 2021 · 1 comment

Comments

@aemitos
Copy link
Contributor

aemitos commented Dec 30, 2021

Hi
We added the deprecate_field to a foreign key field and it doesn't generate a migration for the change.
Is it related to the foreign key or because it's Django 3.2.9?
Here is the sample code:

    category = deprecate_field(
        models.ForeignKey(
            ModelCategory,
            on_delete=models.SET_NULL,
            null=True,
            blank=True,
            db_index=True,
            verbose_name=("Category (Deprecated)"),
        )
    )

We are already good to remove the field but we were following the recommended on https://github.com/3YOURMIND/django-migration-linter/blob/main/docs/incompatibilities.md#arrow_forward-dropping-a-column
But we can't make the linter happy. We wonder if it's because of the missing migration to deprecate the field.

@David-Wobrock
Copy link
Contributor

HI @aemitos !

On top of my head, I think deprecate_field is not generating a migration because the FK field is already nullable. The library will only generate a migration if this property changes on the field.

So, to "remove" the column safely, you shouldn't remove it at all.
For now, mark it as deprecated in order to ensure that you are not using it anymore in your code base.
Once you are sure of this (empirically), you can delete the column and generate the drop migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants