V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
doggg
V2EX  ›  Python

alembic 怎么取消参数绑定?

  •  
  •   doggg ·
    vm-001 · 2019-04-15 16:55:43 +08:00 · 1311 次点击
    这是一个创建于 1809 天前的主题,其中的信息可能已经有所发展或是发生改变。
    from alembic import op
    
    op.execute("""
    	INSERT INTO test values('{\"min\":10,\"max\":50,\"unitPrice\":150}');
    """)
    
    

    使用 alembic 作为数据库的版本管理,有时候需要在 alembic 中插入一些初始化的配置,如果有 json 数据,比如上面的语句,:10 会被认为是参数绑定(:age ),对 py 生态完全不熟,有什么办法取消参数绑定吗?

    2 条回复    2019-04-16 11:22:51 +08:00
    claysec
        1
    claysec  
       2019-04-15 21:09:52 +08:00
    看看 op 里面有没有 json 的转换。
    我在这里查找到 mysql 的包里有关于 json 插入数据库的转换功能
    https://www.linuxidc.com/Linux/2017-03/141865.htm
    ```
    tsql.format(json=MySQLdb.escape_string(d_json));
    ```
    doggg
        2
    doggg  
    OP
       2019-04-16 11:22:51 +08:00
    @claysec 不是的。上面的 INSERT INTO 语句是从 Navicat 导出生成的。SQL 是没问题的。只是 :10 这样的格式被 alembic 认为是参数绑定。导致 elambic 里面找不到 10 这个变量出错了。不知道怎么取消参数绑定。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5108 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:16 · PVG 09:16 · LAX 18:16 · JFK 21:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.