Opened 10 years ago
Closed 10 years ago
#23978 closed Bug (duplicate)
Migrations call callable field defaults only once for all rows
Reported by: | Rowan Seymour | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | 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 you add a field with a callable default to an existing model, e.g.
def generate_uuid(): return unicode(uuid4()) class Foo(models.Model): uuid = models.CharField(max_length=36, unique=True, default=generate_uuid)
You'll get a migration like...
migrations.AddField( model_name='foo', name='uuid', field=models.CharField(default=foo.models.generate_uuid, max_length=36, unique=True), preserve_default=True, ),
The default function is called only once to get a single default value for all rows, which in this case will fail because the column has a unique constraint.
Note:
See TracTickets
for help on using tickets.
Duplicate of #23408