使用 peewee 进行模式迁移以创建新模型

Schema migrations using peewee to create new models

我真的很喜欢 ORM peewee 的轻量级和简单性。但是现在我正在尝试在数据库中实现模式迁移,我觉得 peewee 在这方面可能有点受限。根据我在文档中的理解,peewee 迁移支持更改现有模型的架构,例如 add_not_nulladd_column。我想知道 peewee 中是否有任何操作可用于添加或删除模型。或者是否有任何其他图书馆可以帮助解决这个问题?提前致谢。

指向 peewee 操作或第 3 方库

Peewee 本身具有创建和删除表的功能:

class MyModel(Model):
    ...

# Create tables
database.create_tables([MyModel, OtherModel, ...])

# Drop tables
database.drop_tables([MyModel, OtherModel, ...])

http://docs.peewee-orm.com/en/latest/peewee/api.html#Database.create_tables