我想增加表中最后一个id的值,这样我就可以在下一行输入不同的值。我在我的python项目中使用oracle 11g数据库。请参阅我的示例代码......
custID = Customer.objects.lates('CUSTOMER_ID')
custID = int(custID) + 1 #received error
custName = "Peter"
Customer.objects.create('CUSTOMER_ID'=str(custID), 'CUSTOMER_NAME'=custName) #this line is ok
我收到了这个错误:TypeError: int() argument must be a string, a bytes-like object or a number, not 'Customer'
我尝试在线搜索并更改了我的代码,如
Customer.objects.create('CUSTOMER_NAME'=custName)
但没有奏效,因为我的数据库和python模型没有自动递增。
我也试过了..
custID = sum(int(custID), 1)
抱歉,我是django的新人。
答案 0 :(得分:1)
好吧,如果我理解正确,这是你的问题:
custID = Customer.objects.latest('CUSTOMER_ID')
此语句将返回Customer
对象,因此您需要使用
custId = custID.CUSTOMER_ID + 1
答案 1 :(得分:1)
Customer.objects.latest('CUSTOMER_ID')
返回一个对象,而不是id。你想要的是这个:
custID = Customer.objects.latest('CUSTOMER_ID').id
但是,在创建新客户时,您不需要指定ID;通常Django会自己获取id。