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

Remove a Foreign key field from a model #188

Closed
aemitos opened this issue Dec 30, 2021 · 1 comment · Fixed by #192
Closed

Remove a Foreign key field from a model #188

aemitos opened this issue Dec 30, 2021 · 1 comment · Fixed by #192
Assignees

Comments

@aemitos
Copy link

aemitos commented Dec 30, 2021

Hi
We don't know if it's related to the fact that the deprecate_field for a foreign key field is not generating a migration for the change (3YOURMIND/django-deprecate-fields#21).
We couldn't find any steps describing how to remove a foreign key and that's why we open this issue.
We are on Django 3.2.9.
And if we remove the field that it is not being referenced anymore. Generate the migration and run it to remove the field we can see in the database that the field is removed successfully.
We could try to ignore the linter but we wonder if it has a way to make the linter happy. The issue is that we use the linter in our CI/CD and it's failing the builds. It complains about the dropping field operation:

❯ ./manage.py makemigrations --check
Migrations for 'our_app':
  our_app/migrations/0110_remove_category.py
    - Remove field category from modelcategory
Linting for 'our_app':
[30-Dec-2021 13:48:04] [INFO/django_migration_linter] [MESSAGE: Calling sqlmigrate command our_app 0110_remove_category]
(our_appa, 0110_remove_category)... ERR
	DROPPING columns (table: ourapp_ourmodel, column: category_id)

The migration linter detected that this migration is not backward compatible.
- If you keep the migration, you will want to fix the issue or ignore the migration.
- By default, the newly created migration file will be deleted.
Do you want to keep the migration? [y/N]
@David-Wobrock David-Wobrock self-assigned this Jan 9, 2022
@David-Wobrock
Copy link
Collaborator

Hi @aemitos !

This is one of the cases where I'd recommend to ignore the generated migration (if it only contains the FK column drop).

The linter cannot really know if one is just dropping a column unconsciously or if the column is actually unused.
Therefore => dropping a column raises as a linting error.

So if you are certain that the field is unused (and that during deployment you won't generate errors by dropping the column), you can safely ignore the migration for linting :)
See https://github.com/3YOURMIND/django-migration-linter/blob/main/docs/usage.md#ignoring-migrations that would probably be the easiest way to ignore the migration

It's true that https://github.com/3YOURMIND/django-migration-linter/blob/main/docs/incompatibilities.md#arrow_forward-dropping-a-column is not very explicit about the process there. I'll add some information 👍

I hope that helps :)

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

Successfully merging a pull request may close this issue.

2 participants