I am trying `GeneratedField` on Django 5.0 in a project running on Oracle
Database 19c Enterprise Edition, Version 19.18.0.0.0. My real use case is
bit more complicated so made up a simpler one - I have
`ts_password_changed` as `DateTimeField(blank=True, null=True)` and I'm
trying to add generated boolean field:
{{{
is_password_changed = GeneratedField(
expression=ExpressionWrapper(Q(ts_password_changed__isnull=False),
output_field=models.BooleanField()),
output_field=models.BooleanField(),
db_persist=False
)
}}}
The generated migration SQL looks like this:
{{{
ALTER TABLE "CORE_USER" ADD "IS_PASSWORD_CHANGED" NUMBER(1) GENERATED
ALWAYS AS ("TS_PASSWORD_CHANGED" IS NOT NULL) VIRTUAL;
}}}
and Oracle refuses it with
{{{
ORA-54016: Invalid column expression was specified, Position 81
}}}
However, it works when I modify the query to
{{{
ALTER TABLE "CORE_USER" ADD "IS_PASSWORD_CHANGED" NUMBER(1) GENERATED
ALWAYS AS (CASE WHEN "TS_PASSWORD_CHANGED" IS NOT NULL THEN 1 ELSE 0 END)
VIRTUAL;
}}}
which is probably what Django should be generating.
--
Ticket URL: <https://code.djangoproject.com/ticket/35018>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.