How to add comments to table or column in mysql using SQLAlchemy?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 04:43:52

问题


I want to add comments a tabble and columns created.

so I add doc parameter to the constructor of SQLAlchemy Column class.

But do not add comments the column.

class Notice(db.Model):
    __tablename__ = "tb_notice"
    __table_args__ = {'mysql_engine': 'MyISAM'}

    seqno = db.Column(db.Integer, primary_key=True, autoincrement=True, doc="seqno")
    title = db.Column(db.String(200), nullable=False, doc="notice title")
    detail = db.Column(db.TEXT, nullable=True, doc="notice detail ")

And I wonder how to add the comment of table.


回答1:


comment only supported in version 1.2 New in version 1.2: http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.Column.params.comment




回答2:


in new 1.2 version you can do

class Notice(db.Model):
    __tablename__ = "tb_notice"
    __table_args__ = {
        'mysql_engine': 'MyISAM'
        'comment': 'yeah comment'
    }


来源:https://stackoverflow.com/questions/38709800/how-to-add-comments-to-table-or-column-in-mysql-using-sqlalchemy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!