gpt4 book ai didi

sql-server - 在Django数据库中插入多个值-原始sqlite语句

转载 作者:行者123 更新时间:2023-12-03 18:43:10 25 4
gpt4 key购买 nike

我在Django中使用原始SQL。

p.execute('''INSERT INTO webapp_information VALUES(login=%s, idd=%s, avatar_url=%s, gravatar_id=%s, url=%s, html_url=%s, followers_url=%s, following_url=%s, gists_url=%s, starred_url=%s, subscriptions_url=%s, organizations_url=%s, repos_url=%s, events_url=%s, received_events_url=%s,typ=%s,site_admin=%s, name=%s, company=%s, blog=%s, location=%s,email=%s, hireable=%s, bio=%s, public_repos=%s, public_gists=%s, followers=%s, following=%s, created_at=%s, updated_at=%s, dat=%s''',i)


我是值列表
遵循文档 https://docs.djangoproject.com/en/2.1/topics/db/sql/中给出的自定义sql


    /usr/local/lib/python2.7/dist-packages/django/db/backends/utils.pyc in execute(self, sql, params)
77 start = time()
78 try:
---> 79 return super(CursorDebugWrapper, self).execute(sql, params)
80 finally:
81 stop = time()

/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.pyc in execute(self, sql, params)
62 return self.cursor.execute(sql)
63 else:
--> 64 return self.cursor.execute(sql, params)
65
66 def executemany(self, sql, param_list):

/usr/local/lib/python2.7/dist-packages/django/db/utils.pyc in __exit__(self, exc_type, exc_value, traceback)
92 if dj_exc_type not in (DataError, IntegrityError):
93 self.wrapper.errors_occurred = True
---> 94 six.reraise(dj_exc_type, dj_exc_value, traceback)
95
96 def __call__(self, func):

/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.pyc in execute(self, sql, params)
62 return self.cursor.execute(sql)
63 else:
---> 64 return self.cursor.execute(sql, params)
65
66 def executemany(self, sql, param_list):

/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.pyc in execute(self, query, params)
335 return Database.Cursor.execute(self, query)
336 query = self.convert_query(query)
--> 337 return Database.Cursor.execute(self, query, params)
338
339 def executemany(self, query, param_list):

OperationalError: near "?": syntax error


我从没用过'?' django要求使用'%s'的地方
该怎么办..谢谢

最佳答案

您的i变量必须是列表
我= [...]
p变量是一个游标对象
p.execute('插入或替换成
webapp_information(登录,idd,avatar_url,gravatar_id,url,html_url,followers_url,following_url,gists_url,starred_url,subscriptions_url,organizations_url,repos_url,events_url,received_events_url,typ,site_admin,名称,公司,博客,位置,电子邮件,可租用public_repos,public_gists,关注者,关注者,created_at,updated_at,dat)VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,% s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s)',i)

关于sql-server - 在Django数据库中插入多个值-原始sqlite语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51952736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com