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:
- Is it, actually, a problem of the connector? Or I'm missing something here?
- Is there a way to use the same code in Windows than in Linux? (maybe only adding the dialect and the connector on Linux)
- Should I program everything from now on, specifying the conversion
float()
every-time I write a float into the database?
Any clue to those questions is more than welcome.
question from:
https://stackoverflow.com/questions/65898746/windows-linux-sqlalchemy-connector-conversion-type-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…