Chris
Chris

Reputation: 12181

DB not persisting after end of program

I've created a simple DB using SQLAlchemy. After I connect to it via the engine, define the tables and classes, then create a User, it outputs the user fine. When the program ends and I try accessing the DB via the Python prompt (importing SQLAlchemy, creating a new engine, etc.) the previous users are gone.

Can someone explain what is happening here, and what (if anything) is in the previously set-up .db file?

Upvotes: 0

Views: 78

Answers (1)

Larry Lustig
Larry Lustig

Reputation: 51000

Are you calling .commit() on the connection before releasing it?

By default the Python SQLite module does not use AUTOCOMMIT mode and, unless you finish your session with a DDL statement, it will be rolled back.

For more info: http://docs.python.org/library/sqlite3.html#controlling-transactions.

Upvotes: 4

Related Questions