Answer the question
In order to leave comments, you need to log in
How to get through the rake garden when migrating from SQLite3 to MySQL in Django or "not enough arguments for format string" when building raw queries?
I've been trying to migrate a Django project from SQLite to MySQL for almost a week. I 've already gone through a rake garden with SQL server settings, host, remote access, firewall, data transfer, differences in field sizes and index building ... And here is the last (hopefully) rake with "not enough arguments for format string":
There is a raw- request:
from project.models import my_model
import re
import urllib
def Autocomplete_Addr ( request ):
msg = u""
SQLquery = u""
part = re.split ("[, /;|]*", urllib.unquote(request.GET['term']))
for i in part[:-1]:
SQLquery += u"(sAddress LIKE '%%%s%%') AND " % i
SQLquery += u"(sAddress LIKE '%%%s%%') " % part[-1]
SQLquery = u"SELECT id, sAddress " + \
u"FROM project_adress_list " + \
u"WHERE " + SQLquery +\
u"ORDER BY sAddress " \
u"LIMIT 10;"
qu = my_model.objects.raw(SQLquery)
for i in qu:
msg += '"' + i.sAddress + u'",'
Exception Value: not enough arguments for format string
for i in qu:
qu = my_model.objects.raw(SQLquery)[:10]
Answer the question
In order to leave comments, you need to log in
The issue was resolved after a complete transfer of all data and rebuilding of all indexes.
In the SQLite database, the strings "something" and "something" (difference in the trailing space) are considered unique. In mySQL, such rows are not unique. This seems to be the reason for all the problems.
PS The difference in the speed of query execution through ORM and RAW for MySQL is not as significant as in SQLite. Which speaks more about the quality of the ORM and not the database itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question