文章内容
2025/2/23 22:51:17,作 者: 黄兵
TypeError: create_table_comment() takes 2 positional arguments but 3 were given
最近在使用 SQLAlchemy 的时候,对 SQLAlchemy 模型注释进行更改的时候,同步模型与 MySQL 数据库,出现了如下错误:
TypeError: create_table_comment() takes 2 positional arguments but 3 were given
具体错误代码:
with op.batch_alter_table('cloud_user_notification_types', schema=None) as batch_op:
batch_op.create_table_comment(
'cloud_user_notification_types',
'用户公告类型',
existing_comment=None,
schema=None
)对此错误询问 DeepSeek 应该如何解决:

我们将错误信息告诉 DeepSeek 之后,看看 DeepSeek 能够给我们什么好的建议:

代码改的乱七八糟,我们直接全部采纳建议,看看:

通过对比可以看出,绿色部分是 DeepSeek 给我们更改之后的代码,红色部分是原来的代码,我们直接更新数据库,看看能否可行?

好像最后更新完成,并没有出现错误。
当然这个错误,我们也可以这样修改:
with op.batch_alter_table('cloud_user_notification_types') as batch_op:
batch_op.create_table_comment(
comment='用户公告类型',
existing_comment=None,
)这里我们主要查看源代码 create_table_comment() 这个函数需要传递那些参数:

需要说明:我这里使用的是 PyCharm,插件使用的是腾讯云 AI 代码助手。
评论列表