3

我正在使用 Python 3.3 32 位在 Windows 上工作。我已经安装了 peewee 并想尝试它的一些功能。我从 Peewee 快速入门 ( http://peewee.readthedocs.org/en/latest/peewee/quickstart.html ) 开始。

我的代码如下所示:

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 安装有问题吗?我该如何解决这个问题?

4

1 回答 1

5

Peewee兼容 Python 3;它目前仅适用于 Python 2。

您看到的错误是由此造成的;该类Model使用 Python 2 技术定义了一个元类,该技术已针对 Python 3 进行了更改。

更新:2013-04-02 发布的2.1 版增加了 Python 3 兼容性。该软件包现在支持 Python 2.6、2.7 和 3.2 及更高版本。

于 2013-03-24T12:33:41.997 回答