gpt4 book ai didi

python - 类型错误 : __init__() missing 1 required positional argument: 'model'

转载 作者:行者123 更新时间:2023-11-30 22:12:06 27 4
gpt4 key购买 nike

初学者问题。我有一个基本上将帖子与用户相关联的类:

class Post(Model):
timestamp = DateTimeField(default=datetime.datetime.now)
user = ForeignKeyField(
rel_model=User,
related_name='posts'
)
content = TextField()

class Meta:
database = DATABASE
order_by = ('-timestamp',)

当它到达 'lated_name='posts' 行时,我收到此错误:

Traceback (most recent call last):
File "app.py", line 5, in <module>
import forms
File "/dev/forms.py", line 2, in <module>
from models import User
File "/dev/models.py", line 41, in <module>
class Post(Model):
File "/dev/models.py", line 45, in Post
related_name='posts'
TypeError: __init__() missing 1 required positional argument: 'model'

我使用的数据库是Sqlite(带有Peewee)。我不明白当 Model 是父类时,为什么它要求位置参数“model”。我错过了什么?

最佳答案

如果您使用的是 Peewee 3.x,则:

class Post(Model):
timestamp = DateTimeField(default=datetime.datetime.now)
user = ForeignKeyField(
model=User,
backref='posts')
content = TextField()

class Meta:
database = DATABASE

注意:Peewee 3.x 不支持 Meta.order_by。

关于python - 类型错误 : __init__() missing 1 required positional argument: 'model' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51224092/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com