How to insert to postgres using Django ORM when a generated index field exists

A text field is on one of my models. For search purposes, I’ve made an index on this field:

class my_model(models.Model):  

   text = models.TextField(null=True)
   vector = SearchVectorField(null=True, default='')

I have so far just used the insert command to add data to this table, and I did not supply any data for the column at the time of insertion. Everything was fine, but now this model has a many-to-many field. I want to update the insert function to use Django ORM as I haven’t created an explicit through table. I’m having trouble since I’m getting an error when I try to use ORM to enter the following statement into the model:

a1 = my_model(text='test')


ProgrammingError: column "vector" can only be updated to DEFAULT
DETAIL:  Column "vector" is a generated column.

Also, i tried the following with the same error:

a1 = my_model(text='test', vector = '')

Thanks in advance.

PostgreSQL: Documentation: 12: 5.3. Generated Columns

Looks like you can’t put vector into the model, because Django will try to write it to the database.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.