Schema qualified tables with SQLAlchemy, SQLite and Postgresql?

Posted by Chris Reid on Stack Overflow See other posts from Stack Overflow or by Chris Reid
Published on 2010-04-21T19:19:31Z Indexed on 2010/04/21 19:23 UTC
Read the original article Hit count: 383

Filed under:
|
|
|
|

I have a Pylons project and a SQLAlchemy model that implements schema qualified tables:

class Hockey(Base):
    __tablename__ = "hockey"
    __table_args__ = {'schema':'winter'}
    hockey_id = sa.Column(sa.types.Integer, sa.Sequence('score_id_seq', optional=True), primary_key=True)
    baseball_id = sa.Column(sa.types.Integer, sa.ForeignKey('summer.baseball.baseball_id'))

This code works great with Postgresql but fails when using SQLite on table and foreign key names (due to SQLite's lack of schema support)

sqlalchemy.exc.OperationalError: (OperationalError) unknown database "winter" 'PRAGMA "winter".table_info("hockey")' ()

I'd like to continue using SQLite for dev and testing.

Is there a way of have this fail gracefully on SQLite?

© Stack Overflow or respective owner

Related posts about sqlalchemy

Related posts about pylons