mgear
mgear

Reputation: 1908

web2py database always locked when trying to update from code

Trying to simply update existing row in database (running on web2py), but always getting database locked error..

Error message:

<class 'sqlite3.OperationalError'> database is locked

My setup

Software

What i've tried so far


Error log: http://pastebin.com/2WMWypt6


Current workaround: - Create New Application, exact same code seems to work there


Solution was: by @GauravVichare - Remove this line from controller (its already defined in db.py)

db = DAL('sqlite://storage.sqlite',pool_size=10,auto_import=True)

Upvotes: 0

Views: 1046

Answers (3)

Gaurav Vichare
Gaurav Vichare

Reputation: 1183

Check Whether there is no other connection (to sqlite db) open on your machine, if web2py shell is open, close it.

Check DAL is defined only once or not. Define DAL only in models/db.py, no need to define it again in controller.

Every variable defined in models is visible in controllers.

You must have defined DAL in models/db.py and you are defining once again in controller, so you have two connection open for SQLite db. Thats why you are getting error 'database is locked'.

Upvotes: 1

EoinS
EoinS

Reputation: 5482

Try using myRecord instead of Record, since it may be a reserved word.
I know User has given people issues in web2py. I would just tend to stay away from very generic aliases.

Otherwise, is there anything currently in the db? If it is empty you would receive and error.
It might be better to :

myRecord = record = db(db.mytest).select().first()

if myRecord:
  myRecord.update_record(name="asdfg")
else:
  [insert statement here]

Upvotes: 0

Sharan Kumar
Sharan Kumar

Reputation: 15

My Suggestion is

1.First of all save the code when u make some changes.

2.Aftr saving u r new code try to reload web2py.exe then run web2py so that u wont get Databaselocked error.

3.Dont ever create tables in Sqlite database before.

4.once u start running web2py and starts server and when ever u enter data into forms it automatically creates the tablesin sqlite database.

Upvotes: 0

Related Questions