Opened 5 years ago

Closed 5 years ago

#30527 closed Bug (invalid)

Problem with creating migrations for subclassed field changes.

Reported by: Wolfgang Fehr Owned by: nobody
Component: Migrations Version: dev
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

makemigrations gives out 'No changes detected' for changes on a sub-subclass of CharField (only tested with this field).

When creating a field as seen below (DummyCharField), a new migration only gets created if kwargs['max_length'] = 255 is wrapped inside an if.

class BaseDummyCharField(models.CharField):
    def __init__(self, *args, **kwargs):
        if 'max_length' not in kwargs:
            kwargs['max_length'] = 64
        super().__init__(*args, **kwargs)


class DummyCharField(BaseDummyCharField):
    def __init__(self, *args, **kwargs):
        # Without the if 'makemigrations' does not recognize changes.
        # Previous max_length (in initial migration) is 64.
        if 'max_length' not in kwargs:
            kwargs['max_length'] = 255
        super().__init__(*args, **kwargs)


class DummyModel(models.Model):
    dummy = DummyCharField()

(Also reproducable in version 2.0.6, maybe others as well.)

Change History (3)

comment:1 by Mariusz Felisiak, 5 years ago

Component: Core (Management commands)Migrations
Resolution: invalid
Status: newclosed
Summary: Problem with creating migrations for subclassed field changesProblem with creating migrations for subclassed field changes.
Version: 2.2master

You're use case is described in Writing custom model fields documentation. It seems that deconstruct() is missing which is very important for migrations.

Closing per TicketClosingReasons/UseSupportChannels.

comment:2 by Wolfgang Fehr, 5 years ago

Resolution: invalid
Status: closednew

I tried out deconstruct(), but still had the same problem. (also see Stackoverflow)
(also tried deconstruct() in the parent-field)

comment:3 by Carlton Gibson, 5 years ago

Resolution: invalid
Status: newclosed

This is still not a support channel. See TicketClosingReasons/UseSupportChannels.

Note: See TracTickets for help on using tickets.
Back to Top