简体   繁体   English

在Peewee中使用“.select()”方法的麻烦

[英]Trouble with “.select()” Method in Peewee

I am making a peewee database. 我正在制作一个peewee数据库。 In my python code I try to retrieve rows from the model that may be empty: 在我的python代码中,我尝试从模型中检索可能为空的行:

player_in_db = Player.select().where(Player.name == player.name_display_first_last)

Player is the name of the model Player是模型的名称

name is a field instance in Player defined... namePlayer定义的字段实例...

class Player(Model):
      name = CharField()

player.name_display_first_last is a string player.name_display_first_last是一个字符串

I get an error that says peewee.OperationalError: no such column: t1.name 我收到一个错误,上面写着peewee.OperationalError: no such column: t1.name

I've been trying to solve this problem for the bulk of today, but to no avail. 我一直试图在今天的大部分时间里解决这个问题,但无济于事。 Any help would be much appreciated. 任何帮助将非常感激。 Let me know if you need any more information to help me. 如果您需要更多信息来帮助我,请与我们联系。 Thanks. 谢谢。

The error says you're missing the name column in the table (named t1 ) that your Player model uses. 该错误表示您缺少Player模型使用的表(名为t1 )中的name列。 Most likely you've told PeeWee to create the table for player before it had the name field or you simply haven't created the table at all. 很可能你已经告诉PeeWee在它有名字字段之前为玩家创建表格,或者根本就没有创建表格。 You should always try to fully write your model before creating it's table. 在创建表之前,您应该始终尝试完全编写模型。

If you're just using test data for now, you can use drop_table() to delete the entire table and then re-create it with create_tables() . 如果您现在只使用测试数据,可以使用drop_table()删除整个表,然后使用create_tables()重新创建它。

drop_tables(Player)
create_tables([Player])

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

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