[Django] #29987: Deleting non-managed model does not generate a DeleteModel in migrations

11 views
Skip to first unread message

Django

unread,
Nov 25, 2018, 9:46:55 PM11/25/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
--------------------------------------+------------------------
Reporter: dbowring | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
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
[https://github.com/django/django/blob/d6226e3a821a5132c61233c8df767810ce00f851/django/db/migrations/autodetector.py#L701
django.db.migrations.autodetector])

--
Ticket URL: <https://code.djangoproject.com/ticket/29987>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 25, 2018, 9:54:14 PM11/25/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------

Reporter: dbowring | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* keywords: => autodetector managed model delete
* stage: Unreviewed => Accepted


Comment:

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:1>

Django

unread,
Nov 26, 2018, 4:23:21 PM11/26/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: Tim
| Fiedler
Type: Bug | Status: assigned
Component: Migrations | Version: 2.1

Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Fiedler):

* status: new => assigned
* owner: nobody => Tim Fiedler


--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:2>

Django

unread,
Nov 26, 2018, 5:08:26 PM11/26/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: Tim
| Fiedler
Type: Uncategorized | Status: assigned
Component: Migrations | Version: 2.1

Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Fiedler):

* type: Bug => Uncategorized


Comment:

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


}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:3>

Django

unread,
Nov 26, 2018, 5:09:12 PM11/26/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: (none)
Type: Uncategorized | Status: new
Component: Migrations | Version: 2.1

Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Fiedler):

* owner: Tim Fiedler => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:4>

Django

unread,
Nov 26, 2018, 5:42:01 PM11/26/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:5>

Django

unread,
Nov 26, 2018, 7:15:08 PM11/26/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 2.1
Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


Comment:

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!

--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:6>

Django

unread,
Nov 27, 2018, 4:37:22 PM11/27/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------

Reporter: Daniel Bowring | Owner: Tim
| Fiedler
Type: Bug | Status: assigned
Component: Migrations | Version: 2.1

Severity: Normal | Resolution:
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Fiedler):

* status: new => assigned
* needs_better_patch: 1 => 0
* owner: (none) => Tim Fiedler


--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:7>

Django

unread,
Nov 30, 2018, 10:31:09 AM11/30/18
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: Tim
| Fiedler
Type: Bug | Status: closed
Component: Migrations | Version: 2.1
Severity: Normal | Resolution: fixed

Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"b07273a0f710c0ed00ccbc1c555b4f1e5d6fc662" b07273a]:
{{{
#!CommitTicketReference repository=""
revision="b07273a0f710c0ed00ccbc1c555b4f1e5d6fc662"
Fixed #29987 -- Detected unmanaged model deletions.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:8>

Django

unread,
Apr 10, 2019, 7:28:45 AM4/10/19
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: Tim
| Fiedler
Type: Bug | Status: closed
Component: Migrations | Version: 2.1

Severity: Normal | Resolution: fixed
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Andi Albrecht):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:9>

Django

unread,
Apr 10, 2019, 8:21:20 AM4/10/19
to django-...@googlegroups.com
#29987: Deleting non-managed model does not generate a DeleteModel in migrations
-------------------------------------+-------------------------------------
Reporter: Daniel Bowring | Owner: Tim
| Fiedler
Type: Bug | Status: closed
Component: Migrations | Version: 2.1

Severity: Normal | Resolution: fixed
Keywords: autodetector | Triage Stage: Accepted
managed model delete |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Bugfixes are not mentioned in release notes for major releases.

--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:10>

Reply all
Reply to author
Forward
0 new messages