我一直试图生成以下sql代码,用于使用sqlalchemy在表中创建MySQL列:
`win` tinyint(1) unsigned NOT NULL DEFAULT '0'我使用这个作为我的sqlalchemy语句:
class Matches(Base):
"""matches entity class"""
__tablename__ = 'matches'
__table_args__ = {
'mysql_engine': 'InnoDB',
'mysql_charset': 'utf8'
}
win = Column(TINYINT(1, unsigned=True), nullable=False, default=0)但是,这不会生成我只想要的默认值:
win TINYINT(1) UNSIGNED NOT NULL另外,当我设置默认值=‘CURRENT_TIMESTAMP’(在另一列中)时,它会自动添加我不想要的on更新。我是不是遗漏了什么?
另外,作为一个附带的问题,我将如何使用sqlalchemy生成这样的东西:
UNIQUE KEY `matchid` (`match_id`)我知道该列有一个惟一的bool属性,它将生成唯一的部分,但是当我使用列属性key='matchid‘时,似乎什么都没有发生。
发布于 2013-12-05 07:34:13
见server_default和unique of 列
win = Column(TINYINT(1, unsigned=True), nullable=False, default=0,
server_default=text('0'),
unique=True,
)https://stackoverflow.com/questions/20390686
复制相似问题