0

I use the raw sql in django..

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)


i is the list of values
follow the custom sql given in the documentation https://docs.djangoproject.com/en/2.1/topics/db/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


i never used the '?' where the django asked to use '%s' what to do.. thanks

2
  • Why are you doing this as raw SQL? It's a simple insert, which maps straight onto a model create call Commented Aug 21, 2018 at 16:27
  • How to do that.. <br> And It is also easier to use the raw sql statements.. so I used it but got error.. and how to resolve it.. thanks Commented Aug 21, 2018 at 17:38

1 Answer 1

2

Your i variable must be a list i=[...] p variable is a cursor object p.execute('INSERT OR REPLACE INTO webapp_information(login, 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, name, company, blog, location, email, hireable, bio, public_repos, public_gists, followers, following, 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)',i)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.