gpt4 book ai didi

python - Peewee 在运行时注册一个新模型

转载 作者:行者123 更新时间:2023-11-29 13:55:36 26 4
gpt4 key购买 nike

我希望能够连接到数据库 (PostgreSQL),其中 url 和凭据作为参数接收,而无需事先了解该方案。所以我已经知道我可以像这样在 python 中创建新类型:

MyModel = type('MyMdel', (peewee.Model,))

然后添加新的 Peewee 字段:

my_field = peewee.IntegerField(null=False, default=0)
my_field.add_to_class(MyModel, 'my_field_name')

但这在 peewee 中行得通吗?

最佳答案

这对我来说是正确的。您遇到任何问题吗?

关于python - Peewee 在运行时注册一个新模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32763594/

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