{{{
class Company(models.Model):
name = models.CharField(max_length=250)
class Client(models.Model):
name = models.CharField(max_length=250)
company = models.ForeignKey(
Company,
on_delete=models.DO_NOTHING,
default=Company.objects.last
)
}}}
{{{
django/db/migrations/serializer.py", line 169, in serialize
raise ValueError(
ValueError: Could not find function last in django.db.models.manager.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34288>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
* component: Migrations => Database layer (models, ORM)
Comment:
This was fixed in 46efd03d2674084051f7ce04006e95520649a1ac. However, as
[https://docs.djangoproject.com/en/stable/ref/models/fields/#default
documented]:
> ''"The default can’t be a mutable object (**model instance**, list, set,
etc.), ..."''
> ''"For fields like ForeignKey that map to model instances, defaults
should be the value of the field they reference (pk unless to_field is
set) **instead of model instances**."''
so the default cannot be a model instance.
Duplicate of #33733.
--
Ticket URL: <https://code.djangoproject.com/ticket/34288#comment:1>