Below is my code
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
# models.py
class DbBasedFile(models.Model):
filename = models.CharField(_('filename'), max_length=128)
content = models.BinaryField(_('content'))
size = models.PositiveIntegerField(_('size'))
class Meta:
unique_together = (('filename', ), )
def __str__(self):
return '{}, filename: {}'.format(self.__class__.__name__,
self.filename)
if __name__ == '__main__':
DbBasedFile(filename='1.txt', content=b'abc', size=3).save()
}}}
}}}
will get error
{{{
ProgrammingError at /api/misc/dbfiles/file/
(1064, "You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'_binary'abc', 3)'
}}}
The pre-generated sql is like below
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
str: INSERT INTO `misc_dbbasedfile` (`filename`, `content`, `size`)
VALUES (%s, _binary %s, %s)
}}}
}}}
The final sql is like below
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
bytes: b"INSERT INTO `misc_dbbasedfile` (`filename`, `content`, `size`)
VALUES ('1.txt', _binary _binary'abc', 3)"
}}}
}}}
As we can see, there are two ''''_binary''' in the final sql which will
fail eventually
After a little debugging, I found these '''_binary''' in
{{{
django/django/db/backends/mysql/operations.py.DatabaseOperations.binary_placeholder_sql
django/db/models/fields/__init__.py.BinaryField.get_placeholder
}}}
, which I think is the root cause
Please kindly help to fix it, thx.
--
Ticket URL: <https://code.djangoproject.com/ticket/27816>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Tim Graham):
Are you using the latest version of mysqlclient? There's
[https://github.com/PyMySQL/mysqlclient-python/pull/106 a bug] in some
older versions.
--
Ticket URL: <https://code.djangoproject.com/ticket/27816#comment:1>
Comment (by Ace Han):
Replying to [comment:1 Tim Graham]:
> Are you using the latest version of mysqlclient? There's
[https://github.com/PyMySQL/mysqlclient-python/pull/106 a bug] in some
older versions.
Hi,
I just went with {{{PyMySQL==0.7.9}}}, I don't know there is a
{{{mysqlclient}}}.
However, I would prefer {{{PyMySQL}}} for its python implementation.
Anyway, isn't this issue related with {{{django}}} itself in
{{{django/django/db/backends/mysql}}}?
--
Ticket URL: <https://code.djangoproject.com/ticket/27816#comment:2>
* status: new => closed
* resolution: => invalid
Comment:
I think PyMySQL needs to adapt as explained in [https://github.com/PyMySQL
/mysqlclient-python/pull/106 the mysqlclient issue]. By the way, it's not
an officially supported or tested adapter by Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/27816#comment:3>