大家好,我用 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
请问有人遇到么
1
ljdawn OP MySqlPrimaryKeyAutoIncrementField 这个字段不是很要紧,只是为了跟自己代码保持一致,所以放上来了。
|