Only DB2, MS-SQL, Ingres and Informix have support for keyed tables so
far as per the note in
http://web2py.com/book/default/chapter/06#Legacy-Databases-and-Keyed-Tables

But it can be added with fairly little effort, see section E) in
http://groups.google.com/group/web2py/browse_thread/thread/db150376b06d47fc


On Dec 18, 5:34 am, sushanth <sushant...@gmail.com> wrote:
> Hi,
>
> How to create a primary key as name  as filed not id,right now i have
> exiting mysql schema in that string is PK and connected FK to other string
> field.i am design  a app in web2py in that  creating models using existing
> schema but  web2py is creating only id as PK default.
>
> Can you please help on this
>
> db=DAL('mysql://root:test1234...@localhost/new')
>
> db.define_table('dogs',
>     Field('owner_id','id'),
>     Field('teamname'),primarykey=['owner_id','teamname'],
>     migrate=False,
>      )
>
> db.define_table('users',
>     Field('num','id'),  
>     Field('name'),
>     Field('team',db.users),primarykey=['num','team'],
>     migrate=False,
>     )
>
> db.users.name.requires = IS_NOT_EMPTY()
> db.users.team.requires = IS_IN_DB(db, 'dogs.teamname', ' dogs_teamname')
>
> error :
>
> Traceback (most recent call last):
>   File "/home/sushanth/Desktop/web2py/gluon/restricted.py", line 188, in 
> restricted
>     exec ccode in environment
>   File "/home/sushanth/Desktop/web2py/applications/newone/models/db.py" 
> <http://127.0.0.1:8000/admin/default/edit/newone/models/db.py>, line 13, in 
> <module>
>     Field('team',db.users),primarykey=['num','team'],
>   File "/home/sushanth/Desktop/web2py/gluon/sql.py", line 1400, in __getattr__
>     return dict.__getitem__(self,key)
> KeyError: 'users'
>
> Thanks in advance

Reply via email to