gpt4 book ai didi

sqlalchemy.exc.ProgrammingError : (ProgrammingError) relation does not exist

转载 作者:行者123 更新时间:2023-12-03 17:53:00 25 4
gpt4 key购买 nike

我正在通过创建新项目来尝试 Pyramid。我选择 PostgreSQL 和 sqlalchemy。现在我有一个手动创建的表格“照片”和一个模型:

class Photo(Base):
""" The SQLAlchemy declarative model class for a Photo object. """
__tablename__ = 'photo'

id = Column(Integer, primary_key=True)
name = Column(Text)
filename = Column(Text)
cat_id = Column(Integer)
viewed = Column(Integer)
created = Column(DateTime)

def __init__(self, name):
self.name = name

然后在 View 中我尝试过滤一些记录:
walls = DBSession.query(Photo).filter(Photo.cat_id == 20).limit(10)

但是这一小段代码不起作用,我有一个错误:
[sqlalchemy.engine.base.Engine][Dummy-2] {'param_1': 1, 'cat_id_1': 20}
*** sqlalchemy.exc.ProgrammingError: (ProgrammingError) relation "photo" does not exist
LINE 2: FROM photo
^
'SELECT photo.id AS photo_id, photo.name AS photo_name, photo.filename AS photo_filename, photo.cat_id AS photo_cat_id, photo.viewed AS photo_viewed, photo.created AS photo_created, photo.amazon_folder AS photo_amazon_folder \nFROM photo \nWHERE photo.cat_id = %(cat_id_1)s \n LIMIT %(param_1)s' {'param_1': 1, 'cat_id_1': 20}

数据库连接 url 正确:
sqlalchemy.url = postgres://me:pwd@localhost:5432/walls

有什么建议?

最佳答案

你可以试试,

Photo.query.filter_by(cat_id = 20).limit(10).all()

关于sqlalchemy.exc.ProgrammingError : (ProgrammingError) relation does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16509092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com