Thankyou Derek,
I will give it a try , but this was only a simple, cut down, test case to 
get it to work initially.   I originally had a string for the PK, and I 
also wanted to test multi column PKs.  
I am confident the 'id' will work, but it doesn't address the other 
scenarios.   My real goal is to change another base adaptor, but I'm using 
MSSQL as my baseline as it is supposed to work OK.
The next thing I will try is to do some db interaction without forms or 
grids.  I think that might be where the issue is.   
Thanks again.

On Thursday, March 29, 2012 10:50:41 AM UTC+13, Derek wrote:
>
> Try changing your field1 type to 'id'.
> like this:
> Field('Field1', 'id'),
>
> On Tuesday, March 27, 2012 10:56:44 PM UTC-7, Andrew wrote:
>>
>> Hello,
>> I posted on this issue some time ago and I'm pretty sure it was working 
>> again after a fix from DenesL.
>> However I can't get Primary Key tables in MSSQL to work.  They get 
>> created OK, but I get errors with a Form in a view.
>> I originally made the Key a string, but then switched to integer just to 
>> see if it made a difference.  :
>>
>> *Model:*
>> dbSQL = DAL('mssql://....)
>> # 1 Column PK
>> dbSQL.define_table('web2py_int_PK',
>>                 Field('Field1', 'integer'),
>>                 Field('Field2', 'string', length=20),
>>                 format='%(Field1)s',
>>                 primarykey = ['Field1'],
>>                 migrate=True)
>>
>> *Controller:*
>> def web2py_int_PK_form():
>>     form = SQLFORM(dbSQL.web2py_int_PK)
>>     if form.process().accepted:
>>         response.flash = 'form accepted'   
>>     elif form.errors:       
>>         response.flash = 'form has errors'   
>>     else:       
>>         response.flash = 'please fill out the form'
>>     return dict(form=form)     
>>
>> *View:*
>> {{extend 'layout.html'}}
>> <h1>Primary Key Form Test</h1>
>> {{=form}}
>>
>> I get this in the ticket:
>> File "D:\Mercurial\web2py\gluon\dal.py", line 6912, in __getitem__
>> return dict.__getitem__(self, str(key))
>> KeyError: '_id'
>>
>> It looks like it is trying to retrieve the value for "_id" , but looking 
>> at the code __init__ for a table, _id never gets set for a table with a 
>> Primary Key.  (look at lines 6752, 6762, 6772).
>>
>> Just wondering if something like line 772 in sqlhtml.py (In the SQLFORM 
>> __init__ method).          "self.id_field_name = table._id.name"  could 
>> cause the above lookup of the _id key ?  Do Forms work with keyed tables ?
>>
>> Thanks
>> Andrew W
>>
>>
>>

Reply via email to