5

I'm trying Pyramid by creating the new project. I choose PostgreSQL and sqlalchemy. For now I have a table "photo" created manually and a model for it:

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

Then in a view I trying to filter some records:

walls = DBSession.query(Photo).filter(Photo.cat_id == 20).limit(10)

But this small bunch of code doesn't work, I had an error:

[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}

DB connection url is correct:

sqlalchemy.url = postgres://me:pwd@localhost:5432/walls

Any suggestions?

James May
  • 1,371
  • 3
  • 20
  • 37
  • 1
    Are you SURE the SQL tables are created with the same names as you provided to SQLAlchemy? The table in PostgreSQL isn't actually called "photos" or "Photo"? (See answer on [this question](http://stackoverflow.com/questions/695289/cannot-simply-use-postgresql-table-name-relation-does-not-exist)) – Mark Hildreth May 12 '13 at 15:57
  • I had the same error whose reason is incorrect schemas and tables owners, i.e. it's permission problem for my case. – kupgov Jan 06 '17 at 23:23

1 Answers1

-1

You can try,

Photo.query.filter_by(cat_id = 20).limit(10).all()
Chirag Vora
  • 242
  • 3
  • 10