推荐学习书目
› 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 · Apr 15, 2019 · 2356 views
    This topic created in 2719 days ago, the information mentioned may be changed or developed.
    from alembic import op
    
    op.execute("""
    	INSERT INTO test values('{\"min\":10,\"max\":50,\"unitPrice\":150}');
    """)
    
    

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

    2 replies  •  2019-04-16 11:22:51 +08:00
    claysec
        1
    claysec  
       Apr 15, 2019
    看看 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
       Apr 16, 2019
    @claysec 不是的。上面的 INSERT INTO 语句是从 Navicat 导出生成的。SQL 是没问题的。只是 :10 这样的格式被 alembic 认为是参数绑定。导致 elambic 里面找不到 10 这个变量出错了。不知道怎么取消参数绑定。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2502 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 04:08 · PVG 12:08 · LAX 21:08 · JFK 00:08
    ♥ Do have faith in what you're doing.