ote that currently this is only available for DB2, MS-SQL, Ingres and
Informix, but others can be easily added.

At the time of writing, we cannot guarantee that the primarykey attribute
works with every existing legacy table and every supported database
backend. For simplicity, we recommend, if possible, creating a database
view that has an auto-increment id field.

Here what the book says... Do you have a compatible DMS?

Richard

On Wed, Feb 8, 2012 at 2:45 PM, Omi Chiba <ochib...@gmail.com> wrote:

> I have legacy table called IQWAGFTY which doesn't have id field so I
> specify primarkey for the existing field.
>
> I received KeyError: 'TYPRCD' for crud.updae but not crud.create. What
> am I doing wrong or is it not supported to update with primarykey ?
>
> Model
> -------------
> db.define_table('IQWAGFTY',
>    Field('TYPRCD', length=15, label="Product Code:"),
>    Field('TYPRKJ', length=50, label="Part Number:"),
>    Field('TYTYPE', length=2, label="Type:"),
>    Field('TYFLAG', length=1, default=""),
>    Field('TYUUSR', length=128, default = auth.user.username.upper()
> if auth.user else None, label="Updated by:"),
>    Field('TYUDAT', 'datetime', default=request.now, label="updated
> on:"),
>    primarykey=['TYPRCD'])
>
> Contoller (update:NG)
> ------------------------------
> def test():
>    return dict(form=crud.update(db.IQWAGFTY,
> db.IQWAGFTY(db.IQWAGFTY.TYPRCD=='000115126002200')))
>
> TRACEBACK:
> Traceback (most recent call last):
>  File "D:\web2py\gluon\restricted.py", line 194, in restricted
>    exec ccode in environment
>  File "D:/web2py/applications/Inventory_Reserve_Admin/controllers/
> default.py", line 111, in <module>
>  File "D:\web2py\gluon\globals.py", line 149, in <lambda>
>    self._caller = lambda f: f()
>  File "D:\web2py\gluon\tools.py", line 2456, in f
>    return action(*a, **b)
>  File "D:/web2py/applications/Inventory_Reserve_Admin/controllers/
> default.py", line 68, in test
>    return dict(form=crud.update(db.IQWAGFTY,
> db.IQWAGFTY(db.IQWAGFTY.TYPRCD=='000115126002200')))
>  File "D:\web2py\gluon\tools.py", line 2978, in update
>    detect_record_change = self.settings.detect_record_change):
>  File "D:\web2py\gluon\sqlhtml.py", line 1033, in accepts
>    record_id = dict((k, request_vars[k]) for k in
> self.table._primarykey)
>  File "D:\web2py\gluon\sqlhtml.py", line 1033, in <genexpr>
>    record_id = dict((k, request_vars[k]) for k in
> self.table._primarykey)
> KeyError: 'TYPRCD'
>
>
> Contoller(create:OK)
> -----------------------------
> def test():
>    return dict(form=crud.create(db.IQWAGFTY))
>
>
>

Reply via email to