PythonSQLAlchemy使用exists()检查表中是否已有数据?

2024-10-01 13:34:07 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有下面的Feeds类

class Feeds(DeclarativeBase):
    __tablename__ = "rawFeeds"

    id = Column(Integer, primary_key=True)
    link = Column('link', String)
    date = Column('date', String)
    source = Column('source', String)

def __init__(self, link, date, source):
    self.link = link
    self.date = date
    self.source = source

我想运行一个检查表中是否已经存在数据(以避免添加重复项)。我使用下面的语句,但无论我尝试什么,它总是产生一个真实的结果

^{pr2}$

谁能帮我弄清楚我做错了什么吗?我反复阅读了SQLAlchemy文档,但是我不知道这里的错误是什么。谢谢。在


Tags: keyselfidsourcedatestringlinkcolumn