这个错误是由于在使用Alembic迁移时尝试在非as_sql模式下使用literal_binds来设置绑定参数引起的。在非as_sql模式下,Alembic默认会将绑定参数转换为字符串进行展示,而不是真正的绑定参数。
要解决这个问题,可以通过在Alembic配置文件中添加一个render_as_batch选项来修改默认行为。将render_as_batch设置为True后,Alembic会在非as_sql模式下使用literal_binds来设置绑定参数。
下面是一个示例的Alembic配置文件:
# alembic.ini
[alembic]
script_location = alembic
sqlalchemy.url =
[alembic:render_as_batch]
# Set render_as_batch to True
render_as_batch = True
在这个配置文件中,render_as_batch被设置为True,这样在非as_sql模式下使用literal_binds来设置绑定参数。
请确保将替换为你的数据库连接URL。
使用这个配置文件运行Alembic迁移时,就不会再出现无法在非as_sql模式下使用literal_binds设置的错误了。