Search code examples
mysqlmysql-pythonmysql-connector-python

Why am I getting error 1264: Out of range value for column 'ping' at row 1?


size of the ping is 10,

table data is {'ping': 48.68, 'download': 0.41, 'upload': 0.12}

then how come float value of size 5 throwing error:

mysql.connector.errors.DatabaseError: 1264: Out of range value for column 'ping' at row 1

Here is my mysql table

+----------------+--------------+------+-----+-------------------+----------------+
| Field          | Type         | Null | Key | Default           | Extra          |
+----------------+--------------+------+-----+-------------------+----------------+
| id             | int(11)      | NO   | PRI | NULL              | auto_increment |
| ping           | float(10,10) | YES  |     | NULL              |                |
| download       | float(10,10) | YES  |     | NULL              |                |
| upload         | float(10,10) | YES  |     | NULL              |                |
| datetime_added | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
+----------------+--------------+------+-----+-------------------+----------------+

Solution

  • Type:

    Floating-Point Types

    MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). Here, (M,D) means than values can be stored with up to M digits in total, of which D digits may be after the decimal point.

    So: float(10,10) does not allow for storing 48.68. Before decimal point could be only 0.

    db<>fiddle demo