5

I'm using SQLModel for FastAPI. But I don't know how to create 'text' column type using it.

How can I create 'text' column? Thank you for reading it.

from sqlmodel import SQLModel, Field


class BaseModel(SQLModel):
    col_1: str = Field(default='Y')
    col_2: str = Field(default='N')
    col_3: str = Field(default='0')
    col_4: str = Field(default='0')

this is my solution!

from sqlmodel import SQLModel, Field
from sqlalchemy import Column, TEXT


class BaseModel(SQLModel):
    col_5: str = Field(sa_column=Column(TEXT))
1

1 Answer 1

4

Try this:

from sqlalchemy.dialects.postgresql import TEXT

from sqlmodel import SQLModel, Field
from sqlalchemy import Column


class BaseModel(SQLModel):
    col_5: str = Field(sa_column=Column(TEXT))
Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget to add sqlalchemy into your requirements.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.