I've been working in a project that uses SQLAlchemy to work with a MySQL database. I've done all the tests in my Windows machine. The problem had come when I moved the project to the Ubuntu server 20.04. There I got the following error: Python 'float64' cannot be converted to a MySQL type
. Doing some research I've found this similar case. The suggestion is just to use int()
or float()
to convert numbers explicitly. But a question still remains: Why should it work on windows and not on Linux?
Doing more research I've found that it is probably a problem of the connector, which it is not the same in Windows and Linux. Actually I had some previous problems because in Windows I instantiate the engine: db_config = 'mysql://{}:{}@localhost/{}?charset=utf8mb4'.format(db_user, db_pass, db_schema)
, this is, only specifying the dialect and not the connector. While in Linux, only work if I specify both: db_config = 'mysql+mysqlconnector://{}:{}@localhost/{}?charset=utf8mb4'.format(db_user, db_pass, db_schema)
On Windows I'm using the connector PyMySQL
with Xampp 7.1.9
and DB 10.1.26-MariaDB
with the engine InnoDB
. On Linux I use the connector mysqlconnector
with the server MySQL 8.0.22-0ubuntu0.20.04.3
and also the engine InnoDB
. It is worth to mention that I only have troubles when a float64
is written on the DB.
So, after this long introduction (sorry for it) the specific questions are:
float()
every-time I write a float into the database?Any clue to those questions is more than welcome.
Thanks to @snakecharmerb I reallize that I only need to use the same connector. So everything get solved by using on Linux: mysql+pymysql://{}:{}@localhost/{}?charset=utf8mb4'.format(db_user, db_pass, db_schema)
. This is, using the connector PyMySQL
instead of mysqlconnector
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.