Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29987 closed Bug (fixed)

Deleting non-managed model does not generate a DeleteModel in migrations

Reported by: Daniel Bowring Owned by: Tim Fiedler
Component: Migrations Version: 2.1
Severity: Normal Keywords: autodetector managed model delete
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you have a model like:

class NonManagedModel(models.Model):
    some_field = models.TextField()

    class Meta:
        managed = False

and run makemigrations, a migration including a CreateModel will be generated

$ python3 manage.py makemigrations nmapp
Migrations for 'nmapp':
  nmapp/migrations/0001_initial.py
    - Create model NonManagedModel

However, if you remove the model from models.py, no migration with a DeleteModel is created

$ python3 manage.py makemigrations nmapp
No changes detected in app 'nmapp'

It seems like the intention was to include this for unmanaged models, but is being skipped (see django.db.migrations.autodetector)

Change History (10)

comment:1 by Simon Charette, 6 years ago

Keywords: autodetector managed model delete added
Triage Stage: UnreviewedAccepted

I haven't reproduced but looking at the auto-detector code that seems like a legitimate report. Would you be interested in providing a patch to get it fixed?

comment:2 by Tim Fiedler, 6 years ago

Owner: changed from nobody to Tim Fiedler
Status: newassigned

comment:3 by Tim Fiedler, 6 years ago

Type: BugUncategorized

I had provide a PR which for sure needs some tests. But to be honest now i'm thinking of the idea of a unmanaged model. Or to be precise... Is this a realy a bug ? Regarding the Documentation this seems to be a desired behaviour:)

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


Last edited 6 years ago by Tim Graham (previous) (diff)

comment:4 by Tim Fiedler, 6 years ago

Owner: Tim Fiedler removed
Status: assignednew

comment:5 by Tim Graham, 6 years ago

Type: UncategorizedBug

comment:6 by Simon Charette, 6 years ago

Has patch: set
Patch needs improvement: set

Thanks for the quick patch Tim!

Left a few comments for improvement on the PR. Please uncheck Patch needs improvement once you've addressed them.

Thanks!

comment:7 by Tim Fiedler, 6 years ago

Owner: set to Tim Fiedler
Patch needs improvement: unset
Status: newassigned

comment:8 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In b07273a:

Fixed #29987 -- Detected unmanaged model deletions.

comment:9 by Andi Albrecht, 6 years ago

Shouldn't this be mentioned in the release notes for 2.2? It took me a while to figure out why I have new migrations after upgrading to 2.2.

comment:10 by Mariusz Felisiak, 6 years ago

Bugfixes are not mentioned in release notes for major releases.

Note: See TracTickets for help on using tickets.
Back to Top