Opened 9 months ago
Closed 9 months ago
#33168 closed Cleanup/optimization (wontfix)
Meta.managed=False field not respected by makemigrations
Reported by: | Javier Domingo Cansino | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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
Change History (6)
comment:1 Changed 9 months ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 9 months ago by
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
comment:3 Changed 9 months ago by
Migrations should be generated for unmanaged models (to track their state), however, running the migration should have no effect on the database.
comment:4 Changed 9 months ago by
Resolution: | invalid |
---|---|
Status: | closed → new |
I have opened https://github.com/django/django/pull/14934 to clarify this in the documentation
comment:5 Changed 9 months ago by
Component: | Migrations → Documentation |
---|---|
Type: | Bug → Uncategorized |
comment:6 Changed 9 months ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
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.
Unmanaged models are tracked in migrations but database operations for unmanaged models aren't performed.