我在 mysql 中有一个 DB 模式
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)
我正在尝试使用以下查询在数据库中插入值
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 查询中编写。
谢谢