sqlite3.OperationalError: no such table:

2,069 views
Skip to first unread message

Terrence Brannon

unread,
Feb 13, 2017, 1:34:52 PM2/13/17
to web2py-users
Hello, I created the following RDBMS schema in the file db.py

from pydal import DAL, Field
from datetime import datetime

db = DAL('sqlite://gridtrader.db')

grid = db.define_table(
    'grid',
    Field('market'),
    Field('pickle', type='text'),
    Field('timestamp', type='datetime', default=datetime.now)
    )

# db.executesql('CREATE INDEX IF NOT EXISTS grid_market_idx ON grid (market);')

db.commit()

And then I attempted to insert a record but got this error:

$ python -i
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
>>> import db
>>> db.grid.insert(market='asdfasdf', pickle='asdfasfd')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\supreme\install\Anaconda2\lib\site-packages\pydal\objects.py", line 741, in insert
    ret = self._db._adapter.insert(self, self._listify(fields))
  File "C:\Users\supreme\install\Anaconda2\lib\site-packages\pydal\adapters\base.py", line 492, in insert
    raise e
sqlite3.OperationalError: no such table: grid
>>> 

Edwin Haver

unread,
Feb 13, 2017, 2:36:03 PM2/13/17
to web2py-users
Hi Terrence,

Your db.py script has not run and this is why you get the no such table error. I believe that it should work if you run the following command:

python web2py.py -S <APPNAME>

You will then get an interactive shell with the web2py environment and application loaded.

Regards, Edwin

Terrence Brannon

unread,
Feb 13, 2017, 5:56:17 PM2/13/17
to web2py-users
Hi Edwin, I should've stated that I am using pyDAL standalone. And please note that I did an `import db` at the top of the console session, which should've run all the define_table statements in that file, correct?

Edwin Haver

unread,
Feb 14, 2017, 3:56:31 AM2/14/17
to web2py-users
Hi Terrence,

I have tried it your way now and for me a record is inserted. See results below.

C:\Users\edwinh\Documents\web2py\gluon\packages\dal>python -i
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import db
>>> db.grid.insert(market='asdfasdf', pickle='asdfasfd')
1L
>>>

Regards, Edwin
Reply all
Reply to author
Forward
0 new messages