I have a model that is backed by a database table that contains a read-only 
column that is maintained by the database using Postgresql's Generated 
Columns (i.e. using GENERATED ALWAYS AS) - 
see https://www.postgresql.org/docs/current/ddl-generated-columns.html.

When Django saves the model, it tries to set the field, which throws 
`django.db.utils.ProgrammingError: cannot insert into column "_search". 
DETAIL: Column "_search" is a generated column.

Is there any way to tell Django not to attempt to insert that field?

>From what I can tell `editable=False` doesn't prevent Django from trying to 
save it - which makes sense for fields that aren't editable by users but 
are calculated by the model class, e.g. in `save()`.

I know I could set `something like `instance.save(update_fields=[field for 
field in instance._meta.fields if field.name != "_search")` but it would 
need to be set on every save for that model throughout the application, 
which seems like a lot of technical debt and likely to trip up other 
developers as they maintain the application.

Is there anything that I can set on the field instance in the model to tell 
Django that it is maintained by the database?

If not, please can anyone suggest a way to add code to the model to make it 
ignore the field when saving?

Thanks

Roger

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5b17444e-48ad-4bb6-b9b0-43a186ed3525n%40googlegroups.com.

Reply via email to