无法使peewee
使用最简单的示例:
from peewee import *
db = SqliteDatabase('people.db')
class Person(Model):
name = CharField()
birthday = DateField()
is_relative = BooleanField()
class Meta:
database = db # This model uses the "people.db" database.
class Pet(Model):
owner = ForeignKeyField(Person, related_name='pets')
name = CharField()
animal_type = CharField()
class Meta:
database = db # this model uses the "people.db" database
db.connect()
db.create_tables([Person, Pet])
我得到了这个奇怪的错误:
Traceback (most recent call last):
File "D:\EclipseWorkspace\peewee_test.py", line 22, in <module>
db.create_tables([Person, Pet])
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 3448, in create_tables
create_model_tables(models, fail_silently=safe)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 4767, in create_model_tables
m.create_table(**create_table_kwargs)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 4459, in create_table
db.create_table(cls)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 3445, in create_table
return self.execute_sql(*qc.create_table(model_class, safe))
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1865, in inner
return self.parse_node(fn(*args, **kwargs))
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1577, in parse_node
sql, params, unknown = self._parse(node, alias_map, conv)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1551, in _parse
sql, params = self._parse_map[node_type](node, alias_map, conv)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1479, in _parse_clause
node.nodes, alias_map, conv, node.glue)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1594, in parse_node_list
node_sql, node_params = self.parse_node(node, alias_map, conv)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1577, in parse_node
sql, params, unknown = self._parse(node, alias_map, conv)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1551, in _parse
sql, params = self._parse_map[node_type](node, alias_map, conv)
File "D:\Program Files (x86)\Python2.7.3\lib\site-packages\peewee.py", line 1481, in _parse_clause
sql = '(%s)' % strip_parens(sql)
TypeError: Argument 's' has incorrect type (expected basestring, got str)
我已经搜索了一段时间,看起来像是cython
相关的问题,有些建议将cython
更新到最新的稳定版本,但我仍然遇到此错误{ {1}} 0.23.4 ,有谁知道如何解决这个问题?
答案 0 :(得分:0)
好吧,让它工作你可以在循环中创建表
for table in [Pet, Person]:
db.create_table(table)
虽然我必须说我已经用较旧的Cython(0.21.1)对此进行了测试 - 我会看到更新后是否还有可能...这是可能的(0.23.4 )。但我看到你的Python已经很老了,你可能会考虑升级(2.7.10似乎是最新的bugfix 2.7.x发布于2016.01.07)
答案 1 :(得分:0)
找出解决方案。
basestring
是一种新的字符串类型,从cython
0.20 开始,并根据peewee docs:
加速,包括重新实现的各种功能 用Cython。如果是Cython,这个模块将自动构建 安装。
所以基本上playhouse/_speedups.pyd
是在安装过程中使用cython
0.19 构建的,之后我确实将cython
更新为 0.23.4 但它不会对文件产生任何影响。
重新安装/重建peewee
后,现在一切正常。