{{{
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.
* 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>
* status: new => assigned
* owner: nobody => Tim Fiedler
--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:2>
* 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>
* owner: Tim Fiedler => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:4>
* type: Uncategorized => Bug
--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:5>
* 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>
* status: new => assigned
* needs_better_patch: 1 => 0
* owner: (none) => Tim Fiedler
--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:7>
* 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>
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>
Comment (by felixxm):
Bugfixes are not mentioned in release notes for major releases.
--
Ticket URL: <https://code.djangoproject.com/ticket/29987#comment:10>