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