Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Peewee选择子元素不存在的元素_Python_Python 3.x_Orm_Peewee - Fatal编程技术网

Python Peewee选择子元素不存在的元素

Python Peewee选择子元素不存在的元素,python,python-3.x,orm,peewee,Python,Python 3.x,Orm,Peewee,我在一个数据库上操作计算机及其进程 我想选择缺少名为“proc”的进程的计算机 请参阅下面我的尝试: from peewee import * mysql_db = MySQLDatabase('dbname', host='host', port=3306, passwd='passwd') class BaseModel(Model): class Meta: database = mysql_db class Computers(BaseModel):

我在一个数据库上操作计算机及其进程

我想选择缺少名为“proc”的进程的计算机

请参阅下面我的尝试:

from peewee import *

mysql_db = MySQLDatabase('dbname', host='host', port=3306, passwd='passwd')

class BaseModel(Model):
    class Meta:
        database = mysql_db

class Computers(BaseModel):
    computerid = IntegerField(primary_key = True)
    name = CharField()

class Processes(BaseModel):
    processid = BigIntegerField(primary_key = True)
    computerid = ForeignKeyField(Computers, backref = 'processes', db_column='computerid')
    name = CharField()

mysql_db.connect()

proc_computers = (Computers
        .select(Computers, Processes)
        .join(Processes)
        .where(Processes.name == 'proc')
        )

non_proc_computers = (Computers
            .select()
            .where(Computers.computerid.not_in(lttray_computers))
            )
这将导致peewee.InternalError:1241,“操作数应包含1列”

有人能指出我似乎做错了什么吗?我正在尝试按照这里的文档进行操作:

有没有更好的办法


谢谢

您可能希望使用的是:

subq = Process.select().where(
    (Process.name == 'proc') &
    (Process.computer == Computer.id))

query = Computer.select().where(~fn.EXISTS(subq))

注意:最好不要在模型类中使用复数形式。同样,不要在字段名中包含xxx_id。

非常感谢-我还没有机会解决这个问题,但我会尝试一下。我知道使用复数不是最好的做法,但我正在与一个糟糕的预先存在的DB接口,并保持一致。