#23408: Automaticly created migration calls callable for default only once
----------------------------+--------------------
Reporter: Harper04 | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
Callables on properties for ModelFields are used for various reasons. One
use case is to autocreate random file names or user passwords if not
present.
The migration seems to call them only once because after the migration
every "Buchung" has the same wlan_password.
My Model:
{{{
def random_wlan_key():
return
''.join(random.SystemRandom().choice("1234567890abcdefghkmnpqrstuvwxyz")
for i in range(9))
class Buchung(models.Model):
[...]
wlan_passwort = models.CharField(max_length=10,
default=random_wlan_key)
}}}
The generated migration:
{{{
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import main.models
class Migration(migrations.Migration):
dependencies = [
('main', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='buchung',
name='wlan_passwort',
field=models.CharField(default=main.models.random_wlan_key,
max_length=10),
preserve_default=True,
),
]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23408>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.daea97137358bd7b43ee8765a8d9103b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.