문제

I set in DAL(bigint_id=True) since my itemNumber field is being used as primary key in other tables as well. In one particular table, i'm using it as a unique field but not as primary key

mydb.define_table('myitems', 
                    Field('id', 'id',notnull=True,unique=True),
                    Field('itemNumber', 'bigint',notnull=True,unique=True),
                    Field('uniqueTitle', 'string'),

When trying to insert, it always inserts as "0". However, when i print that row, i would see the proper number: example 111078127801

mydb.myitems.update_or_insert(mydb.myitems.itemNumber==int(row),
                              uniqueTitle=fileName)

I did a print int(row) and print row and both show up the proper value. It's during insertion that forces it to 0. I have both tried specifying Field('itemNumber' as bigint and integer and both with the same results.

Thanks,

John

도움이 되었습니까?

해결책

Try:

mydb.myitems.update_or_insert(mydb.myitems.itemNumber==int(row),
                              itemNumber=int(row), uniqueTitle=fileName)

If the first argument is a query, it simply selects the records to be updated (if any). You must still specify all of the field values that you want to insert/update.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top