﻿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
34956	Migration should not be allowed for a non-deterministic GeneratedField	Sarah Boyce	nobody	"Hello hello
I didn't fully understand the GeneratedField and thought I would be able to do something with comparisons against Now (which I ''now'' know I cannot do).

{{{
from django.db import models
from django.db.models import Case, When, Value, Q
from django.db.models.functions import Now


class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField(""date published"")
    closed_date = models.DateTimeField(""date closed"", null=True)
    status = models.GeneratedField(
        expression=Case(
            When(pub_date__lt=Now(), then=Value(""unpublished"")),
            When(Q(closed_date__isnull=False, closed_date__gt=Now()), then=Value(""closed"")),
            default=Value(""active""),
        ),
        db_persist=False,
        output_field=models.TextField(),
    )
}}}

Django allowed me to make migrations and migrate here (I'm using SQLite) but then when I tried to create a Question object it got very angry.
The traceback is very long but the main thing is:


{{{
OperationalError: non-deterministic use of strftime() in a generated column
}}}

I learnt my lesson and won't do it again! But I'm wondering if we can bring this error earlier and prevent the user from being able to makemigrations/migrate? I can provide more details if needed 

"	Cleanup/optimization	closed	Database layer (models, ORM)	5.0	Normal	wontfix			Unreviewed	0	0	0	0	0	0
