[Django] #33168: Meta.managed=False field not respected by makemigrations

291 views
Skip to first unread message

Django

unread,
Oct 4, 2021, 7:29:05 AM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
--------------------------------------------------+------------------------
Reporter: Javier Domingo Cansino | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.2
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 |
--------------------------------------------------+------------------------
I have realised that Meta.managed field when set to False is not being
respected by makemigrations, sample script to reproduce, relies on having
django-admin in the path.

{{{
django-admin startproject sample
cd sample
python manage.py startapp unmanaged
echo 'from django.db import models

class ForeignUnmanagedTable(models.Model):
rowid = models.AutoField(primary_key=True)

class Meta:
managed = False
db_table = "foreign_unmanaged_table"
' > unmanaged/models.py

sed -i '/.*django.contrib.staticfiles.*/a
"unmanaged.apps.UnmanagedConfig", ' sample/settings.py
python manage.py makemigrations
}}}

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

Django

unread,
Oct 4, 2021, 9:19:14 AM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
-------------------------------------+-------------------------------------
Reporter: Javier Domingo | Owner: nobody
Cansino |
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

Unmanaged models are tracked in migrations but database operations for
unmanaged models aren't performed.

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

Django

unread,
Oct 4, 2021, 10:06:44 AM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
-------------------------------------+-------------------------------------
Reporter: Javier Domingo | Owner: nobody
Cansino |
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Javier Domingo Cansino):

I'm not sure if I understand your mesage, but bisecting the problem, it
seems like a change in behaviour between python2 and python3.

Just in case, the problem is that given a model with managed=False,
makemigrations generate migrations for that model. This behaviour is
documented in [1] however it is only respected when running python 2 with
older versions of Django.

[1] https://docs.djangoproject.com/en/3.2/ref/models/options/#managed

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

Django

unread,
Oct 4, 2021, 11:23:46 AM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
-------------------------------------+-------------------------------------
Reporter: Javier Domingo | Owner: nobody
Cansino |
Type: Bug | Status: closed
Component: Migrations | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Migrations should be generated for unmanaged models (to track their
state), however, running the migration should have no effect on the
database.

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

Django

unread,
Oct 4, 2021, 11:32:12 AM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
-------------------------------------+-------------------------------------
Reporter: Javier Domingo | Owner: nobody
Cansino |
Type: Bug | Status: new
Component: Migrations | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Javier Domingo Cansino):

* status: closed => new
* resolution: invalid =>


Comment:

I have opened https://github.com/django/django/pull/14934 to clarify this
in the documentation

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

Django

unread,
Oct 4, 2021, 11:33:22 AM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
-------------------------------------+-------------------------------------
Reporter: Javier Domingo | Owner: nobody
Cansino |
Type: Uncategorized | Status: new
Component: Documentation | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Javier Domingo Cansino):

* type: Bug => Uncategorized
* component: Migrations => Documentation


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

Django

unread,
Oct 4, 2021, 2:25:59 PM10/4/21
to django-...@googlegroups.com
#33168: Meta.managed=False field not respected by makemigrations
-------------------------------------+-------------------------------------
Reporter: Javier Domingo | Owner: nobody
Cansino |
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 3.2
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed

* type: Uncategorized => Cleanup/optimization
* resolution: => wontfix


Comment:

I appreciate you'd like to reopen the ticket, however I don't think that
an extra clarification is needed. It's already documented that:

> ''If False, **no database table creation, modification, 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.**''

We cannot document here all aspects of model handling.

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

Reply all
Reply to author
Forward
0 new messages