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
ljdawn
V2EX  ›  Python

peewee InternalError: (1054, u"Unknown column 't1.pk' in 'field list'")[peewee 小伙伴求助]

  •  
  •   ljdawn · 2017-07-14 22:44:18 +08:00 · 3403 次点击
    这是一个创建于 2471 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大家好,我用 peewee 建标的时候出现一个问题, 当我查询 MyModel.select().first()报错 InternalError: (1054, u"Unknown column 't1.pk' in 'field list'") , 不用 mysql connection pool 的时候没问题. 也可以 MyModel.create(other_field='XXX')新建数据 .

    from peewee import *
    from playhouse.db_url import connect
    mysql_db = connect('mysql+pool://root:[email protected]:3306/test?max_connections=20&stale_timeout=300')
    
    class MySqlPrimaryKeyAutoIncrementField(BigIntegerField):
        def __init__(self, *args, **kwargs):
            kwargs['primary_key'] = True
            super(MySqlPrimaryKeyAutoIncrementField, self).__init__(*args, **kwargs)
    
        def __ddl__(self, column_type):
            ddl = super(MySqlPrimaryKeyAutoIncrementField, self).__ddl__(column_type)
            return ddl + [SQL('auto_increment')]
    
    class MyModel(Model):
        pk = MySqlPrimaryKeyAutoIncrementField()
        other_field = TextField()
        class Meta:
            db_table = 'my_model'
            database = mysql_db
    

    请问有人遇到么

    ljdawn
        1
    ljdawn  
    OP
       2017-07-14 22:51:36 +08:00
    MySqlPrimaryKeyAutoIncrementField 这个字段不是很要紧,只是为了跟自己代码保持一致,所以放上来了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2857 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:25 · PVG 17:25 · LAX 02:25 · JFK 05:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.