127.0.0.1.2017-05-23.17-15-24.8a493eb8-5c35-4dd1-8ade-97ef1e190c7c
web2py™ | Version 2.14.6-stable+timestamp.2016.05.10.00.21.47 |
---|---|
Python | Python 2.7.5: D:\Python\python.exe (prefix: D:\Python) |
1. | Traceback (most recent call last): |
<class 'pyodbc.ProgrammingError'>(('42000', "[42000]
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot update identity
column 'id'. (8102) (SQLExecDirectW)"))
File D:\web2py\gluon\packages\dal\pydal\adapters\base.py in update at line 1031 code arguments variables
(self=<pydal.adapters.mssql.MSSQL2Adapter object>, tablename='amc_master', query=<Query (amc_master.id = 3)>, fields=[(<pydal.objects.Field object>, None), (<pydal.objects.Field object>, 'bid'), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, 3L), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, datetime.datetime(2017, 5, 23, 16, 59, 23)), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), (<pydal.objects.Field object>, None), ...])
1026. | except Exception: |
e |
ProgrammingError('42000', "[42000] [Microsoft][O...e identity column 'id'. (8102) (SQLExecDirectW)") |
---|
Why is DAL trying to update id column in grid edit form submission.
UPDATE xxx SET nid = 1, property0 = :value0 WHERE nid = 1;
.
This is not supported in SQL Server because although there is no actual
update happening it is explicitly telling the database engine that you
wish to perform an update.field_id
must be the field of the table to be used as ID, for example db.mytable.id
.
This is useful when the grid query is a join of several tables. Any
action button on the grid(add record, view, edit, delete) will work over
db.mytable.When I do SQLFORM.grid(db.amc_master) without setting any of the readable/writable attributes the grid edit works fine. I am able to edit and the form submits without errors.
Even with specifying the fields list grid edit works fine as the edit from has all the fields of the table.
But when I set the readable/writable attributes to filter the fields in edit form the the error 42000 listed above occurs.
[setattr(f, 'writable', False) for f in db.
[setattr(f, 'writable', False) for f in db.amc_master
if f.name not in ['id', 'amcdesc', 'amcmod', 'complndays'
]]
But how come it worked fine with postgresql without the id field setting?
Anyway thanks a lot for resolving the issue.