推荐学习书目
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 · Jul 14, 2017 · 4287 views
    This topic created in 3238 days ago, the information mentioned may be changed or developed.

    大家好,我用 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
       Jul 14, 2017
    MySqlPrimaryKeyAutoIncrementField 这个字段不是很要紧,只是为了跟自己代码保持一致,所以放上来了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5368 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 08:43 · PVG 16:43 · LAX 01:43 · JFK 04:43
    ♥ Do have faith in what you're doing.