#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 , 6 years ago
Keywords: | autodetector managed model delete added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 6 years ago
Type: | Bug → Uncategorized |
---|
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
comment:4 by , 6 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:5 by , 6 years ago
Type: | Uncategorized → Bug |
---|
comment:6 by , 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 , 6 years ago
Owner: | set to |
---|---|
Patch needs improvement: | unset |
Status: | new → assigned |
comment:9 by , 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.
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?