sqlalchemy Integer column size

前端 未结 1 1580
一向
一向 2021-01-17 17:40

I saw somewhere that you can define a column size for Integer columns (e.g. Integer(20), Integer(10), etc.) but for some reason, it seems that sqlalchemy ignore those sizes

相关标签:
1条回答
  • 2021-01-17 18:43

    This functionality was deprecated in version 7.

    If you are using MySQL, you can use the mysql.INTEGER datatype:

    from sqlalchemy.dialects import mysql 
    
    class Job(Base):
        __tablename__ = "t_job"
    
        id = Column(mysql.INTEGER(20), Sequence('%s_id_seq' % __tablename__), primary_key=True, nullable=False)
        name = Column(String(30))
        company_id = Column(Integer(20), ForeignKey("t_company.id", ondelete="CASCADE"), nullable=False)
    
    0 讨论(0)
提交回复
热议问题