Django中使用views.py自动递增
if request.method == 'POST':
m = sql.connect(host="localhost",user="root",password="admin@123", database= "ticketsys")
cursor = m.cursor()
ticketid = request.POST['ticketid']
email = request.POST['email']
username = request.POST.get('username')
checkbox = request.POST['checkbox']
adult = request.POST['adult']
fromstation = request.POST['fromstation']
tostation = request.POST['tostation']
rate = request.POST["rate"]
date = request.POST.get('date')
usermessage = request.POST['usermessage']
c = "insert into ticketsys.ticketgen values('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}')".format(ticketid,email,username,checkbox,adult,fromstation,tostation,rate ,date, usermessage)
cursor.execute(c)
m.commit()
return render(request, 'account/ticketconf.html')
else:
return render(request, 'account/ticket.html')
在这里,票证 ID 是自动递增的,但它显示错误。
1366 (HY000): Incorrect integer value: '' for column 'ticketid' at row 1
解决这个问题的最好方法是什么。这样,无需创建模型,我就可以将数据发布到 mysql 中。
if request.method == 'POST':
m = sql.connect(host="localhost",user="root",password="admin@123", database= "ticketsys")
cursor = m.cursor()
ticketid = request.POST['ticketid']
email = request.POST['email']
username = request.POST.get('username')
checkbox = request.POST['checkbox']
adult = request.POST['adult']
fromstation = request.POST['fromstation']
tostation = request.POST['tostation']
rate = request.POST["rate"]
date = request.POST.get('date')
usermessage = request.POST['usermessage']
c = "insert into ticketsys.ticketgen values('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}')".format(ticketid,email,username,checkbox,adult,fromstation,tostation,rate ,date, usermessage)
cursor.execute(c)
m.commit()
return render(request, 'account/ticketconf.html')
else:
return render(request, 'account/ticket.html')
Here, ticket id is auto-increment but its showing me error.
1366 (HY000): Incorrect integer value: '' for column 'ticketid' at row 1
What is best way to solve this problem. so that without creating model I can be able to post my data in mysql.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论