从文档中:http://docs.peewee-orm.com/en/latest/peewee/example.html?highlight=alter http://docs.peewee-orm.com/en/latest/peewee/example.html?highlight=alter
创建表后添加字段将需要您
删除表并重新创建它或手动添加列
使用 ALTER TABLE 查询。
或者,您可以使用架构迁移扩展来更改
使用 Python 的数据库架构。
From http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#migrate http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#migrate:
# Postgres example:
my_db = PostgresqlDatabase(...)
migrator = PostgresqlMigrator(my_db)
title_field = CharField(default='')
status_field = IntegerField(null=True)
migrate(
migrator.add_column('some_table', 'title', title_field),
migrator.rename_column('some_table', 'pub_date', 'publish_date'),
migrator.add_column('some_table', 'status', status_field),
migrator.drop_column('some_table', 'old_column'),
)
还有很多其他操作是可能的。
因此,首先您需要更改表架构,然后可以更新模型以反映这些更改。