SQLForms DAL error

46 views
Skip to first unread message

pumplerod

unread,
Mar 15, 2015, 5:24:15 PM3/15/15
to web...@googlegroups.com
I've found others with this similar error, however the solutions don't seem to apply as far as I can tell in my simplified instance...

# dp.py
db = DAL('sqlite://storage.sqlite')
db.define_table('brands',
    Field('brand_name', type='string', requires=IS_NOT_EMPTY(),
          label=T('brand_name')),
          migrate=True)

# in the controller.py
def brand():
    form = SQLFORM(db.brands)
    return dict(form=form)

# in the brand.html
{{extend 'layout.html'}}
<h2>{{=T( request.args(0).replace('_',' ').capitalize() )}}</h2>
<div id="brand_form">
{{
=form
}}
</div>

I get this error:
    AttributeError: 'DAL' object has no attribute 'brands'


I think I've boiled this down as simple as I can. the table does indeed exist. I'm sure I'm missing something very basic.

Val K

unread,
Mar 16, 2015, 9:41:57 AM3/16/15
to web...@googlegroups.com
Hi!
As I see, you defined your table in the db.py, but 'db=DAL(...) ' is already exist in this file, I mean auth-settings and etc.
If you want to use another database for your tables, I suppose, you must use another storage (not storage.sqlite) and another name for it ('my_db' instead 'db'  for example)

It seems that you have reassignment  'db=DAL(...)'  anywhere.

Dave S

unread,
Mar 16, 2015, 2:07:35 PM3/16/15
to web...@googlegroups.com


On Monday, March 16, 2015 at 6:41:57 AM UTC-7, Val K wrote:
Hi!
As I see, you defined your table in the db.py, but 'db=DAL(...) ' is already exist in this file, I mean auth-settings and etc.
If you want to use another database for your tables, I suppose, you must use another storage (not storage.sqlite) and another name for it ('my_db' instead 'db'  for example)


There shouldn't be any problem with having multiple tables using the same "db=DAL(...)" statement.

In the app I'm working on here on this machine, I have db.py pretty much as shipped by Massimo and the crew (I add another validator to it as the only change).
My application-specific tables are defined in separate model files:  localdb.py, for instance, just contains 1 line (aside from a lot of comments out db.py)
db.define_table('localtable',Field('localtime', 'datetime'), Field('localwho', 'string'), Field('localstatus', 'string'))

Note that model files are read in alphabetical order, so for me db.py gets run first then localdb.py.  And the DAL() call is only run from the db.py.

For a small app, putting the define_table into db.py should be okay, just put it at the bottom of the file.  My app gets new (additional) tables every once and a while, as I find a new use for the server, and its convenient to put those new tables in their own file.  The only gotcha I'm aware of is the order-of-run, so I don't have a "bob.py", I have a "localbob.py".

/dps



Валерий Кучеров

unread,
Mar 16, 2015, 9:26:54 PM3/16/15
to web...@googlegroups.com
You are right! But I mean that possible error's cause is the second assignment 'db=DAL(...) '  (after auth-settings and etc.)

Dave S <snide...@gmail.com> писал(а) в своём письме Mon, 16 Mar 2015 21:07:35 +0300:

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/Pc5NmA9Vytc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Написано с помощью почтового клиента Opera: http://www.opera.com/mail/



Это сообщение свободно от вирусов и вредоносного ПО благодаря avast! Antivirus защита активна.


Dave S

unread,
Mar 16, 2015, 10:04:58 PM3/16/15
to web...@googlegroups.com


On Monday, March 16, 2015 at 6:26:54 PM UTC-7, Val K wrote:
You are right! But I mean that possible error's cause is the second assignment 'db=DAL(...) '  (after auth-settings and etc.)

I thought you might be meaning that, so I was careful to emphasize using just the DAL() line.

/dps

pumplerod

unread,
Mar 17, 2015, 12:30:42 PM3/17/15
to web...@googlegroups.com
Sorry, I'm a bit confused.  I'm under the impression the db=DAL(...) line simply tells web2py which database I will be using.  Then I use db.define_table to create the table.  All of this seems to work because I do see the table listed within the databases directory.  When I try and reference it however I get the error.  As far as I can tell there is only one reference to db=DAL(...) in my code.

I've pretty much cut and pasted the code from the docs...http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM


On Sunday, March 15, 2015 at 4:24:15 PM UTC-5, pumplerod wrote:
I've found others with this similar error, however the solutions don't seem to apply as far as I can tell in my simplified instance...

# db.py

pumplerod

unread,
Mar 17, 2015, 1:00:05 PM3/17/15
to web...@googlegroups.com
My Mistake.  I did indeed find the db=DAL(...) elsewhere located.  Thank you so much for letting me know what to look for.




On Sunday, March 15, 2015 at 4:24:15 PM UTC-5, pumplerod wrote:

Dave S

unread,
Mar 17, 2015, 1:36:41 PM3/17/15
to web...@googlegroups.com


On Tuesday, March 17, 2015 at 10:00:05 AM UTC-7, pumplerod wrote:
My Mistake.  I did indeed find the db=DAL(...) elsewhere located.  Thank you so much for letting me know what to look for.


Glad you were able to get it sorted.

/dps
 
Reply all
Reply to author
Forward
0 new messages