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?
engine.execute("attach database '{db}' as winter;".format(db=_SL_FILE))
to hack around this problem? BTW, I agree with StarShip3000's comment regarding PostgreSQL. – stephanengine.execute("attach database ':memory:' as db_name;")
. I don't know of a way to attach an already existing in-memory db (attaching an existing file-based db to an in-memory one is no problem). So you basically have to change the order of creation: attach the in-memory db first (which creates a new one), and then create tables for this new in-memory db and fill with data as needed. – stephan