检查 table 上是否存在列
Check if column exists on a table
对于上下文:我正在编写一个脚本来执行数据库迁移。
想根据实际 table 检查模型以查看是否所有字段都存在。
或者想运行检查table上是否存在特定列(字段)。
我可以看到 http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.table_exists 存在,所以我正在寻找字段的推论。
提前致谢!
您可以调用 database.get_columns('table_name')
,它将 return table 上的列。
对于上下文:我正在编写一个脚本来执行数据库迁移。
想根据实际 table 检查模型以查看是否所有字段都存在。
或者想运行检查table上是否存在特定列(字段)。
我可以看到 http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.table_exists 存在,所以我正在寻找字段的推论。
提前致谢!
您可以调用 database.get_columns('table_name')
,它将 return table 上的列。