On 08/30/2010 12:00 PM, Benjamin Goll wrote:
Hello Massimo,

I'm using web2py version 1.83.2.

When I define the tables in shell-mode, everything looks fine:

python web2py.py -S aubop -M
db = DAL('sqlite://aubop.db')
db.define_table('track', Field('title'), Field('artist'), Field('length'), 
Field('filepath'))
<Table {'ALL':<gluon.sql.SQLALL object at 0x4344f50>, [...]
db.define_table('album', Field('title'), Field('artist'), Field('tracks', 
'list:reference track'), Field('currentTrack', 'reference track'), 
Field('currentPlaybackTime'), Field('rating', 'integer'))
<Table {'rating':<gluon.sql.Field object at 0x434b290>, [...]
db.tables
['track', 'album']

I then tried to log the output of db.tables immediatelly after the two
db.define_table()s in the model-file "database.py":

db = DAL('sqlite://aubop.db')
db.define_table('track', Field('title'), Field('artist'),
Field('length'), Field('filepath'))
db.define_table('album', Field('title'), Field('artist'),
Field('tracks', 'list:reference track'), Field('currentTrack',
'reference track'), Field('currentPlaybackTime'), Field('rating',
'integer'))
f = open("test.log", "w")
for d in db.tables:
        f.write(d)

Unfortunately the created file is empty. Do you have any idea why?

Regards

Benjamin


If your db.py is like mine then you have the below at the top of the file. If doing this:
db = DAL('sqlite://aubop.db')
in addition to the already defined db then your tables are probably not being created where you think they are. I would suggest a different variable i.e. db2 = DAL('sqlite://aubop.db').



if request.env.web2py_runtime_gae: # if running on Google App Engine
    db = DAL('gae')                           # connect to Google BigTable
session.connect(request, response, db = db) # and store sessions and tickets there
    ### or use the following lines to store sessions in Memcache
    # from gluon.contrib.memdb import MEMDB
    # from google.appengine.api.memcache import Client
    # session.connect(request, response, db = MEMDB(Client()))
else: # else use a normal relational database
    db = DAL('sqlite://storage.sqlite')       # if




--
Adrian Klaver
adrian.kla...@gmail.com

Reply via email to