Upgrading to 1.12 changes type of Mapped[str]
in new migrations
#1472
-
Describe the bug I upgraded Alembic from 1.11.x to 1.13.x. Everything mostly works, except now I'm getting unnecessary conversions of my Expected behavior I expected Alembic to see that the columns are To Reproduce # Example SQLAlchemy table definition
class Example(Base):
__tablename__ = "example"
text: Mapped[str] Error # Generated code in the new migration post 1.12.0
op.alter_column('example', 'text',
existing_type=sa.TEXT(),
type_=sa.String(),
existing_nullable=False) Versions.
Additional context This might not be a bug, and just working as intended. Looking at PostgreSQL's documentation, it says:
It makes sense to me for Alembic to default to Have a nice day! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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:
class Base(DeclarativeBase):
type_annotation_map = {
str: String().with_variant(TEXT, "postgresql"),
}
|
Beta Was this translation helpful? Give feedback.
hi -
this doesnt look like a bug. If you have:
that's the same as:
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:
Mapped[str]
as TEXT at least for PostgreSQL: