pydantic-sqlalchemy icon indicating copy to clipboard operation
pydantic-sqlalchemy copied to clipboard

SQLAlchemy defaults are not present in Pydantic model

Open martinhanzik opened this issue 5 years ago • 1 comments

class TestSchema(Base):
    __tablename__ = 'test'

    id = Column(INTEGER(10, unsigned=True), primary_key=True)
    active = Column(Boolean, default=True, nullable=False)

Test = sqlalchemy_to_pydantic(TestSchema)

Test(id=1)
# Test(id=1)
Test(id=1).dict()
# TestSchema(id=1, active=None)

active should be True

martinhanzik avatar Aug 17 '20 06:08 martinhanzik

是的如果需要这个默认值支持,就需要该源码

M-Qi avatar Jul 07 '22 09:07 M-Qi