0

I am creating a simple app in pyramid . While inserting data i am getting db locked error.

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked [SQL: 'INSERT INTO users (name, email, number) VALUES (?, ?, ?)'] [parameters: ('test', '[email protected]', '123654')]

But first time it inserts the data correctly and on 2nd time it gives this error.

Any idea why this is happening second time ?

Here is my code :

name = request.params['name']
email = request.params['email']
no = request.params['number']
DBSession.add(User(name, email, no))
# Get the new ID and redirect
users = DBSession.query(User).all()
asked Jul 3, 2015 at 13:55

1 Answer 1

1

SQLite can only handle 1 concurrent transaction.

Have you tried commit()before performing a query() then close() to end the session?

name = request.params['name']
email = request.params['email']
no = request.params['number']
DBSession.add(User(name, email, no))
# Commit the transaction if complete
DBSession.commit()
# Get the new ID and redirect
users = DBSession.query(User).all()
# Close the session
DBSession.close()
answered Jul 3, 2015 at 15:00
1
  • One edit , It would be transaction.commit() not DBSession.commit() . Also first import transaction Commented Jul 6, 2015 at 11:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.