OK what's changed with SQLite is that file-based databases no longer use a pool
- NullPool is used by default. So below, if you want some kind of scope to
remain for the life of the Engine you'd need to switch it back to
SingletonThreadPool - however, what would be better is to procure a Connection
from the Engine, then do everything with the Connection (i.e.
metadata.create_all(conn)). Since if you really want some scope declared on a
single SQLite connection that's what you'd need to do in any case.
On Sep 16, 2011, at 11:37 AM, Victor Olex wrote:
> Something's changed with sqlite since 0.6. Once a sqlite engine is
> created to a physical file the usual workaround for schema change does
> not work. It works correctly on sqlite in memory and even when
> reattaching from memory to a file.
>
> from sqlalchemy import Column, Sequence, create_engine, Integer
> from sqlalchemy.ext.declarative import declarative_base
> import os
>
> Base = declarative_base()
> metadata = Base.metadata
>
> class A(Base):
> __tablename__ = 'A'
> __table_args__ = {'schema':'S'}
> id = Column(u'ID', Integer, Sequence('A_PK'), primary_key=True)
>
> e = create_engine('sqlite://', echo=True)
> e.execute("attach database 'test.db' as S;")
> metadata.bind = e
> metadata.create_all() # all good
>
> e = create_engine('sqlite:///test.db', echo=True)
> e.execute("attach database 'test.db' as S;")
> metadata.bind = e
> metadata.create_all() # OperationalError: (OperationalError) unknown
> database "S" 'PRAGMA "S".table_info("A")' ()
> os.remove('test.db')
>
> # the work-around I came up with
> e = create_engine('sqlite://', echo=True)
> e.execute("attach database 'test.db' as S;")
> metadata.bind = e
> metadata.create_all() # works fine again, tables were created in file
>
> Previously (ver. 0.6), the OperationalError would not occur. Neither
> SQLite nor pysqlite version have changed.
>
> --
> Victor Olex
> http://linkedin.com/in/victorolex
> http://twitter.com/agilevic
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.