我有MySQL中的数据库架构哪些错误与这条巨蟒的SQL语句
id int(11) PK AI
apt_id varchar(200)
checkin_date date
checkout_date date
price decimal(10,0)
deposit decimal(10,0)
adults int(11)
source_id int(11)
confirmationCode varchar(100)
client_id int(11)
booking_date datetime
note mediumtext
Related Tables:property (apt_id → apt_id)
booking_source (source_id → id)
我试图用插入在DB值以下查询
self.start_at = datetime.strptime(self.start_at[0:10] + ' ' + self.start_at[11:19], "%Y-%m-%d %H:%M:%S")
self.end_at = datetime.strptime(self.end_at[0:10] + ' ' + self.end_at[11:19], "%Y-%m-%d %H:%M:%S")
x = db.cursor()
sql = """INSERT INTO `nycaptBS`.`booking` (`apt_id`, `checkin_date`, `checkout_date`, `price`,`deposite` `adults`, `source_id`, `confirmationCode`, `client_id`, `booking_date`) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"""
x.execute(sql,(self.apt_id,self.start_at,self.end_at,self.final_price,self.deposit,self.adults,self.source_id,self.notes,self.client_id,self.booking_date,self.notes))
由于错误本身是不明确
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 159, in execute
query = query % db.literal(args)
TypeError: not enough arguments for format string
请帮我解决这个问题。我在Django ORM上工作了很多,但是为此我必须在Mysql查询中编写代码。
感谢
在'x.execute'你只提供四个参数,而不是10,你在查询 – 2013-04-18 05:36:14
等待我会更新我的问题 – burning 2013-04-18 05:40:24
仍然设置了10个占位符,但传递了11个值 – 2013-04-18 05:53:14