Hi,
thank you very much, Adrian! You made my day! :-)
I just replaced "db = DAL('sqlite://storage.sqlite')" by "db2 =
DAL('sqlite://storage.sqlite')" in the file "db.py" and now it works
like a charm!
Thank you too, Massimo for clarifying how web2py handles this.
Problem: solved! :-)
Regards
Benjamin
On 31 Aug., 04:34, mdipierro <[email protected]> wrote:
> when you use the shell to create tables or do anything else you have
> to be db.commit()
>
> the db.define_table() anyway has to be in the model. web2py
> controllers only see tables defined in the models.
>
> On Aug 30, 2:00 pm, Benjamin Goll <[email protected]> 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
>
> > On 30 Aug., 20:38, mdipierro <[email protected]> wrote:
>
> > > which web2py version are you using?
>
> > > what you get if you print db.tables immediately after
> > > db.define_table()
>
> > > On Aug 30, 10:33 am, Benjamin Goll <[email protected]> wrote:
>
> > > > Hello Massimo,
>
> > > > thank you for your fast reply!
>
> > > > Honestly I don't think that this is related to my problem since I only
> > > > tried to demonstrate my problem with this example.
>
> > > > If I define a table in a model, I should be able to access this table
> > > > without any further configuration, right? So when I do the two
> > > > db.define_table()-statements (as shown in my first post), I should be
> > > > able to access the tables in a controller via db.album or db.track
> > > > respectively. Unfortunately this is not the case and results in a
> > > > KeyError. When I do db.tables in a controller, only the auth_*-tables
> > > > are listed.
>
> > > > Is there any possibility to see, if web2py fails while initializing
> > > > the db-object? Setting the debug-level to 0 seems not the help since
> > > > it does not list errors concerning the database.
>
> > > > Regards
>
> > > > Benjamin
>
> > > > On 30 Aug., 16:58, mdipierro <[email protected]> wrote:
>
> > > > > > >>> db = DAL('sqlite://aubop.db')
> > > > > > >>> db.tables
> > > > > > []
> > > > > > That's strange, isn't it?
>
> > > > > this is fine. In fact even if the tables are in db, web2py does not
> > > > > discover them. You still need db.define_table(...) to inform web2py
> > > > > about them.
>
> > > > > I cannot say about the problem with the app, but could it be related
> > > > > to this?
>
> > > > > Massimo
>
> > > > > On Aug 30, 7:56 am, Benjamin Goll <[email protected]> wrote:
>
> > > > > > Hi there,
>
> > > > > > first of all I would like to thank you for this great software! It's
> > > > > > just so much fun to create powerful applications with it!
>
> > > > > > Unfortunately I ran into a really strange problem which I'm not able
> > > > > > to solve.
>
> > > > > > In the file models/database.py I define the following:
>
> > > > > > 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'))
>
> > > > > > When I then try to access one of the two defined tables in a
> > > > > > controller, I receive a KeyError, telling me, that e.g. db.album
> > > > > > cannot be found.
> > > > > > When I open the database "aubop.db" manually via the commandline-
> > > > > > interface of sqlite3, I can see that the two tables have been
> > > > > > created
> > > > > > in the database:
>
> > > > > > sqlite3 aubop.db
> > > > > > sqlite> .tables
> > > > > > album track
>
> > > > > > The sql.log also tells me that the tables ahve been created
> > > > > > successfully.
>
> > > > > > I then started web2py in the shell-mode ("python web2py.py -S aubop
> > > > > > -
> > > > > > M"):
>
> > > > > > >>> db.tables
>
> > > > > > ['auth_user', 'auth_group', 'auth_membership', 'auth_permission',
> > > > > > 'auth_event']>>> db = DAL('sqlite://aubop.db')
> > > > > > >>> db.tables
>
> > > > > > []
>
> > > > > > That's strange, isn't it?
>
> > > > > > Is there anybody who could help me?
>
> > > > > > Btw. access to a different sqlite-database works like a charm in a
> > > > > > second application I've created earlier.
>
> > > > > > Thanks in advance!
>
> > > > > > Regards
>
> > > > > > Benjamin