2013-03-24 125 views
3

我正在使用Python 3.3 32位的Windows上工作。我已經安裝了peewee並想嘗試它的一些功能。我已經開始使用Peewee Quickstart(http://peewee.readthedocs.org/en/latest/peewee/quickstart.html)。peewee:對象沒有屬性_meta

我的代碼如下所示:

from peewee import * 

db = SqliteDatabase('people.db') 

class Person(Model): 
    name = CharField() 
    birthday = DateField() 
    is_relative = BooleanField() 

    class Meta: 
      database = db 

class Pet(Model): 
    owner = ForeignKeyField(Person, related_name = "pets") 
    name = CharField() 
    animal_type = CharField() 

    class Meta: 
      database = db 

Person.create_table() 
Pet.create_table() 

,我得到一個錯誤:

File "<stdin>", line 1, in <module> 
File "<string>", line 21, in <module> 
File "C:\Python33\lib\site-packages\peewee.py", line 2094, in create_table 
db = cls._meta.database 
AttributeError: type object 'Person' has no attribute '_meta' 

是有毛病我安裝的peewee?我該如何解決這個問題?

回答

5

Peewee是不是 Python 3兼容;它目前僅適用於Python 2。

你看到的錯誤是這樣的結果;所述Model類定義使用Python 2的技術的元類,已改變爲Python 3.

更新Version 2.1,2013年4月2日公佈的,添加的Python 3兼容性。該軟件包現在支持Python 2.6,2.7和3.2及更高版本。

+0

太棒了!感謝您的更新! – sebast26 2013-05-06 14:14:52

相關問題