weixin_39890652 2020-11-30 11:22
浏览 0

mysql.TINYINT(display_width=1) vs sa.Boolean()

Migrated issue, originally created by dieselmachine ()

I'm generating diffs that are failing to equate these two types (in autogenerate._compare_columns). I understand the two are not strictly equivalent, but I found this note in the sqlalchemy comments (dialects/mysql/base.py):

"Note: following the usual MySQL conventions, TINYINT(1) columns reflected during Table(..., autoload=True) are treated as Boolean columns."

I am not sure whether the issue lies with sqlalchemy or alembic, but I did some grepping through the sqla code attempting to find where the tinyint was being cast to boolean and I was unable to find anything that looked relevant.

I'd like alembic to not detect these as changes during autogenerate, is there something I need to do in order to have this work?

该提问来源于开源项目:sqlalchemy/alembic

  • 写回答

14条回答 默认 最新

  • weixin_39890652 2020-11-30 11:22
    关注

    dieselmachine () wrote:

    After reading the discussion at https://groups.google.com/group/sqlalchemy/browse_thread/thread/b9c020804456f066 and reviewing the changeset at http://www.sqlalchemy.org/trac/changeset?reponame=&new=95ac46ca88eef268c54357e345a44fc5a930283a%40lib%2Fsqlalchemy%2Fdialects%2Fmysql%2Fbase.py&old=3d0efe038b8543a5ba78871860336346e7b17d96%40lib%2Fsqlalchemy%2Fdialects%2Fmysql%2Fbase.py I can see this behavior was intentional, so I guess it's not really a bug at all.

    You may want to scrub the related comment from the dialects/mysql/base.py file, as the information there is out of date and may lead people to expect unsupported behavior from the Inspector.

    The fix suggested in the linked discussion thread worked for me, and caused the tinyint != boolean ALTER statements to vanish from the migration. Thanks.

    评论

报告相同问题?