[Django] #35549: The Model's Meta option managed doesn't do what the documentation says it should.

32 views
Skip to first unread message

Django

unread,
Jun 21, 2024, 11:13:35 AM6/21/24
to django-...@googlegroups.com
#35549: The Model's Meta option managed doesn't do what the documentation says it
should.
-----------------------------------------+------------------------
Reporter: Tobi-De | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
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'm not sure what I'm doing wrong here. It's something I've noticed for a
while (since Django 4.0), but I didn't think much of it. I thought I was
doing something wrong, but I just created a blank new Django 5 project
(https://github.com/Tobi-De/django_managed_bug), added a new model with
managed = False, and then ran the makemigrations command. It created a
migration for a non-managed model, and running migrate created a table for
that model.

This is what the documentation says about non-managed models:

''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. This
includes''
--
Ticket URL: <https://code.djangoproject.com/ticket/35549>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 21, 2024, 11:17:27 AM6/21/24
to django-...@googlegroups.com
#35549: The Model's Meta option managed doesn't do what the documentation says it
should.
-------------------------------------+-------------------------------------
Reporter: Tobi-De | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
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 Tobi-De):

* component: Uncategorized => Database layer (models, ORM)

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

Django

unread,
Jun 21, 2024, 12:39:59 PM6/21/24
to django-...@googlegroups.com
#35549: The Model's Meta option managed doesn't do what the documentation says it
should.
-------------------------------------+-------------------------------------
Reporter: Tobi DEGNON | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
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 Simon Charette):

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

Comment:

I cannot produce with the project you provided. Django creates a migration
to track the model but the underlying table is not created as documented.

{{{#!sql
SQLite version 3.37.0 2021-12-09 01:34:53
Enter ".help" for usage hints.
sqlite> SELECT * FROM django_migrations WHERE app = 'core';
18|core|0001_initial|2024-06-21 16:34:30.110518
sqlite> .tables
auth_group auth_user_user_permissions
auth_group_permissions django_admin_log
auth_permission django_content_type
auth_user django_migrations
auth_user_groups django_session
}}}

`sqlmigrate` is coherent with that

{{{#!bash
$ ./manage.py sqlmigrate core 0001
BEGIN;
--
-- Create model Book
--
-- (no-op)
COMMIT;
}}}

There is a difference between creating a migration for tracking purposes
and actually creating a table on migration.

Please see TicketClosingReasons/UseSupportChannels for further support.
--
Ticket URL: <https://code.djangoproject.com/ticket/35549#comment:2>

Django

unread,
Jun 21, 2024, 1:01:43 PM6/21/24
to django-...@googlegroups.com
#35549: The Model's Meta option managed doesn't do what the documentation says it
should.
-------------------------------------+-------------------------------------
Reporter: Tobi DEGNON | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
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 Tobi DEGNON):

Replying to [comment:2 Simon Charette]:
My bad, thanks for the clarification, you are right, I was expecting no
migration file to be created
--
Ticket URL: <https://code.djangoproject.com/ticket/35549#comment:3>
Reply all
Reply to author
Forward
0 new messages