﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23408	Add makemigrations warning for unique fields with callable defaults	Harper04	Jacob Walls	"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,
        ),
    ]

}}}
"	New feature	closed	Migrations	dev	Normal	fixed		Markus Holtermann mail@…	Ready for checkin	1	0	0	0	0	0
