简体   繁体   English

psycopg2 中的 Python Alter 语句未更新 Peewee

[英]Python Alter Statement in psycopg2 not updating Peewee

Working on Postgres DB within python using pscopg2, with an ORM of pewee.使用 pscopg2 在 python 中处理 Postgres DB,使用 pewee 的 ORM。 I created the initial tables using pewee and I needed to perform an ALTER statement:我使用 pewee 创建了初始表,并且需要执行 ALTER 语句:

improt psycopg2

cur.execute("ALTER TABLE Test_Table ADD COLUMN filename VARCHAR(100)")
conn.commit()

Which after executed, I do a select * from Test_Table from and the table is present.执行后,我执行 select * from Test_Table from 并且该表存在。

However, when I do a select using the pewee ORM, that column filename does not exist in the Test_Table.但是,当我使用 pewee ORM 进行选择时,Test_Table 中不存在该列文件名。

What do I need to do in order for that ALTER statement to show up using peewee?我需要做什么才能使用 peewee 显示该 ALTER 语句?

Peewee models are not dynamically-created based on the state of the database schema. Peewee 模型不是基于数据库模式的状态动态创建的。 They are declarative.它们是声明性的。

So if you are adding a column to your database, you would add a corresponding field instance to the model class.因此,如果您要向数据库添加一列,则需要向模型类添加相应的字段实例。 Typically this is done offline (eg, not in the middle of while your application is running).通常这是离线完成的(例如,不是在您的应用程序运行期间)。

Refer here for docs on Peewee's schema migration utilities:有关 Peewee 架构迁移实用程序的文档,请参阅此处:

http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#migrate http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM