S
S
Sergey Eremin2015-02-24 14:41:13
MySQL
Sergey Eremin, 2015-02-24 14:41:13

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'",'

Which throws an exception:
Exception Value: not enough arguments for format string

The error occurs in the line: The
for i in qu:
Internet gives a lot of answers about the reasons for this error, but so far checking all of them sequentially shows that the problem does not seem to be somewhere in the area of ​​\u200b\u200b"missing arguments in the line".
PS Perhaps the experts will be led to the answer by the previous "rake". The exact same error occurred on the previous line, when it was slightly different:
qu = my_model.objects.raw(SQLquery)[:10]
By dropping [:10] and adding LIMIT 10 to the raw SQL query, the error was resolved, and... now occurs on the next line!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Eremin, 2015-04-12
@Sergei_Erjemin

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.

A
Andrew, 2015-02-24
@xmdy

Remove raw, use icontains?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question