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

Fixed #29987 -- Detected unmanaged model deletions. #10696

Merged
merged 1 commit into from Nov 30, 2018

Conversation

0x68
Copy link
Contributor

@0x68 0x68 commented Nov 26, 2018

This should fix the problem reported in issue #29987. This is my first contribution on the project. Therfore I have to spend some more time as expected on the tests. I have only used pytest so far

@charettes
Copy link
Member

Hey @0x68! The test should live in test_autodetector.py.

You should be able to create a tests by setting up a from_state and to_state and assert against the from changes = self.get_changes(from_state, to_state).

@charettes charettes changed the title fix check for deleted unmanaged models Fixed #29987 -- Detected unmanaged model deletions. Nov 26, 2018
@0x68
Copy link
Contributor Author

0x68 commented Nov 26, 2018

I have read about the documentation. Seems to be a feature not a bug.

https://docs.djangoproject.com/en/2.1/ref/models/options/

If False, no database table creation or deletion operations will be performed for this model. This is useful if the model represents an existing table or a database view that has been created by some other means. This is the only difference when managed=False. All other aspects of model handling are exactly the same as normal. This includes

@charettes
Copy link
Member

@0x68 the removal of the model should still be tracked. It will result in a noop SQL operation because the model is not managed though.

In other words, the DeleteModel operation should be added to denote the unmanaged model removal from the project state. On application it won't result in any SQL though.

@charettes
Copy link
Member

charettes commented Nov 26, 2018

Here's what causes the actual DROP TABLE to be skipped

if self.allow_migrate_model(schema_editor.connection.alias, model):

if not model._meta.can_migrate(connection_alias):
return False

if self.proxy or self.swapped or not self.managed:
return False

tests/migrations/test_autodetector.py Outdated Show resolved Hide resolved
tests/migrations/test_autodetector.py Outdated Show resolved Hide resolved
django/db/migrations/autodetector.py Outdated Show resolved Hide resolved
@timgraham timgraham force-pushed the 29987-deleting-non-managed-models branch from 4341cee to b07273a Compare November 30, 2018 14:58
@timgraham timgraham merged commit b07273a into django:master Nov 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants