#35813: Makemigrations not properly tracking changes to unmanaged models
-------------------------------------+-------------------------------------
Reporter: Hanny G | Owner: Hanny G
Type: Bug | Status: assigned
Component: Migrations | Version: 5.1
Severity: Normal | Resolution:
Keywords: makemigrations, | Triage Stage: Accepted
unmanaged |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by imakhan):
The purpose of Django's makemigrations command is to identify changes in
managed models, or models in which Django has authority over the database
table structure.
Makemigrations does not completely monitor unmanaged models (where managed
= False in the model's Meta class).
In particular, the makemigrations command does not detect changes to the
fields of unmanaged models, even though the creation or deletion of an
unmanaged model is tracked.
A mismatch between your code and the database structure may result from
this behavior, especially if the model is altered after the initial
transfer.
Unmanaged Model:
Consider you have two models in Django: one is unmanaged and the other is
managed.
class UnmanagedThing(models.Model):
id = models.IntegerField(db_column="thingID", primary_key=True)
thing_number = models.CharField(max_length=16,
db_column="thingNumber")
thing_name = models.CharField(max_length=50, db_column="thingName")
grade_level = models.CharField(max_length=2, db_column="gradeLevel")
class Meta:
managed = False # This tells Django not to manage the table's
structure.
db_table = "some_table_name"
Managemed Model
class ManagedThing(models.Model):
id = models.IntegerField(db_column="thingID", primary_key=True)
thing_number = models.CharField(max_length=16,
db_column="thingNumber")
thing_name = models.CharField(max_length=50, db_column="thingName")
grade_level = models.CharField(max_length=2, db_column="gradeLevel")
class Meta:
managed = True # This tells Django to manage the table's
structure.
Anticipated Conduct: First Migration: Django creates a migration file that
records the construction of the managed and unmanaged models when you
execute makemigrations for the first time.
Modifications to the Managed Model: Django recognizes when you change the
thing_name in the managed model from a CharField to an IntegerField and
generates a migration that takes into account the field change.
Changes in the Unmanaged Model: Django does not detect any changes when
makemigrations are executed if you change thing_name in the unmanaged
model from a CharField to an IntegerField.
--
Ticket URL: <https://code.djangoproject.com/ticket/35813#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701926c469fed-c8a7575a-05d7-488f-bfc3-f30192a1dd0f-000000%40eu-central-1.amazonses.com.