简体   繁体   English

在python中使用peewee数据库出现“没有这样的列”错误

[英]"No such column" error using peewee database in python

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.get(Player.name == player.name_display_first_last)

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

name is a column in Player defined: namePlayer定义的一列:

name = CharField(max_length=25)

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

I then check to see if there are any rows in the player_in_db list:然后我检查player_in_db列表中是否有任何行:

if player_in_db:

I then get an error that says:然后我收到一条错误消息:

sqlite3.OperationalError: no such column: t1.name

I can give you more of the error message if you need, but it's long and references a lot of peewee packages.如果你需要,我可以给你更多的错误信息,但它很长并且引用了很多 peewee 包。

You probably created your table without the name column. 您创建的表可能没有name列。 It's incredibly easy to check. 它非常容易检查。 Just open the sqlite3 shell and run: 只需打开sqlite3 shell并运行:

sqlite3> .schema

Or you can use Peewee's own introspection methods: 或者,您可以使用Peewee自己的自省方法:

db.get_columns('player')

Your model needs to (obviously) correspond to the schema in your actual database... 您的模型(显然)需要与实际数据库中的模式相对应...

您的表“玩家”很可能没有定义主键。

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

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