Composite key in web2py

56 views
Skip to first unread message

Deep Shah

unread,
Aug 20, 2019, 1:00:38 AM8/20/19
to web2py-users
Hi All,
I am migrating table from existing table which has primary key with two fields.
After migrating the table i created SQLFORM.grid and used selectable to process the selected tuples.
selectable = [('Approve Selected names', lambda ids: approve_name(ids))]

Its giving the following error.

<type 'exceptions.AttributeError'> 'Table' object has no attribute '_id'


How do i solve this error keeping both field as key
Thanks and Regards

DISCLAIMER: This email and any attachments transmitted with it may contain confidential, copyrighted, proprietary and legally privileged information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute, print, disclose or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and destroy this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete or virus-free. The sender does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.

Johann Spies

unread,
Aug 20, 2019, 2:16:04 AM8/20/19
to web...@googlegroups.com
On Tue, 20 Aug 2019 at 07:00, Deep Shah <deep...@loylty.com> wrote:
Hi All,
I am migrating table from existing table which has primary key with two fields.
After migrating the table i created SQLFORM.grid and used selectable to process the selected tuples.
selectable = [('Approve Selected names', lambda ids: approve_name(ids))]

Its giving the following error.

<type 'exceptions.AttributeError'> 'Table' object has no attribute '_id'


How do i solve this error keeping both field as key


Just add an id-column as a serial field.  It is not necessary for it to be the primary key. If you need to use the primary key for references, use executesql.

Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

Deep Shah

unread,
Aug 20, 2019, 5:32:54 AM8/20/19
to web2py-users
Data is coming from data source which is cannot be editted and hence cannot add id in table . So is there any other way where i can use table with primary keys?

Dave S

unread,
Aug 20, 2019, 5:25:18 PM8/20/19
to web2py-users


On Tuesday, August 20, 2019 at 2:32:54 AM UTC-7, Deep Shah wrote:
Data is coming from data source which is cannot be editted and hence cannot add id in table . So is there any other way where i can use table with primary keys?


Take a look at
<URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Legacy-databases-and-keyed-tables>

If one of your fields is an auto-increment integer field, you can make it as type 'id'.
Otherwise, maybe "keyed table" will work for you (using a composite of fields that make up the primary key).

You didn't say which DB you have for backend (or did I miss it?) but your DB engine may have been added to the list since that part of the book was updated.

/dps

Reply all
Reply to author
Forward
0 new messages