Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#23574 closed Bug (invalid)

Makemigrations tries to migrate non-model classes

Reported by: Christian Peters Owned by: nobody
Component: Migrations Version: 1.7
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

If your model extends non-model classes, the migration fails with:

raise ValueError("Cannot serialize: %r\nThere are some values Django cannot serialize into migration files.\nFor more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializin

The reason is that before adding the base classes there is no check if the base class is indeed a django model:

https://github.com/django/django/blob/master/django/db/migrations/autodetector.py#L495-505

Solution: Check if the base class is an instance of django.db.model before adding it.

Context:

I have Models with some mixins that just add method and functionality that is shared among multiple models, e.g. an InvoiceMixin, that is shared by multiple models to enrich them with convenience methods.

Change History (3)

comment:1 Changed 5 years ago by Christian Peters

Type: UncategorizedBug

comment:2 Changed 5 years ago by Christian Peters

Resolution: invalid
Status: newclosed

comment:3 Changed 5 years ago by Christian Peters

It turned out, that I just need to inherit the mixin from object to make it work in django 1.7

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