Skip to content

Upgrading to 1.12 changes type of Mapped[str] in new migrations #1472

Answered by zzzeek
knkski asked this question in Usage Questions
Discussion options

You must be logged in to vote

hi -

this doesnt look like a bug. If you have:

# Example SQLAlchemy table definition
class Example(Base):
    __tablename__ = "example"
    text: Mapped[str]

that's the same as:

# Example SQLAlchemy table definition
class Example(Base):
    __tablename__ = "example"
    text = Column(String())

String is VARCHAR. If your PG database has TEXT in it, that suggests that this model was not used to generate the model.

What I would recommend here is, well it depends what you want:

  1. set up Mapped[str] as TEXT at least for PostgreSQL:
class Base(DeclarativeBase):
    type_annotation_map = {
        str: String().with_variant(TEXT, "postgresql"),
    }
  1. turn off the compare_type boolean
  2. use a cust…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by knkski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
Converted from issue

This discussion was converted from issue #1471 on May 08, 2024 05:48.