0

I have a column as such in my model:

class Mem(BaseMem,table=True):
    id: Optional[int] = Field(sa_column=Column(Integer,Identity(always=True,start=1,cycle=True),primary_key=True,nullable=False))
    it_service_instance: Optional[str] = Column(String(),Computed("CASE WHEN environment = 'PROD' THEN it_service ELSE it_service || '-' || environment END",persisted=True),index=True)
    hostname: Optional[str] = Field(default=None,index=True)
    patch_version: Optional[str] = Field(default=None,index=True)
    product_alias: Optional[str] = Field(default=None,index=True)

When I try to autogenerate a migration with alembic i get the following:

op.add_column('mem', sa.Column('it_service_instance', sqlmodel.sql.sqltypes.AutoString(), nullable=True))

Can alembic autogenerated computed columns ?

I am getting this warning:

Computed default on mem.it_service_instance cannot be modified
  util.warn("Computed default on %s.%s cannot be modified" % (tname, cname))
moth
  • 1,833
  • 12
  • 29
  • It works ok with vanilla SQLAlchemy, if I try with SQLModel I get errors about validators so it needs a [mre]. – snakecharmerb Aug 27 '23 at 09:49
  • Does your last edit mean that you are trying to change and existing generated column? I don't think Postgres allows this for non-identity columns - you would need to drop and recreate it. – snakecharmerb Aug 27 '23 at 18:20

0 Answers0