mercredi 6 janvier 2016

Kept getting "incorrect type (expected basestring, got str)" when using peewee to create tables in sqlite database

Couldn't make peewee work with the simplest example:

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])

And I got this weird error:

Traceback (most recent call last):
  File "D:\EclipseWorkspace\SkysTheLimitSoft\Pinvictus\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)

I've searched a while, and looks like it's a cython related problem, some suggested updating cython to the latest stable release, but I still got this error with cython 0.23.4, anybody knows how to fix this problem?

Aucun commentaire:

Enregistrer un commentaire