Reputation: 13914
I am trying to add a large integer to a MySQL
table with SQLAlchemy
. As this answer explains, you cannot pass Integer
a length argument like you can String
. So following that answer I've defined my column with mysql.INTEGER
like so:
from sqlalchemy.dialects import mysql
uniqueid = Column(mysql.INTEGER(20))
When I try to commit an object with a 14 digit uniqueid, however, I get the following error message: DataError: (DataError) (1264, "Out of range value for column 'uniqueid' at row 1")
. When I try a shorter integer that is not a long, it has no problem committing the same object to the SQL database. I am running python 2.7, other discussions of the long
type indicate that it should not behave any differently than int
except for printing an L
at the end of the number. One final piece of information is if I set the uniqueid to the same short number but make it a long, as in uniqueid = long(32423)
, I can still commit the object to the SQL database.
Upvotes: 4
Views: 2628
Reputation: 13914
I did not solve the mystery of why the mysql.INTEGER
class will not work with numbers that have to be long
in python 2.7, but the practical solution is to use SQLalchemy
's BigInteger
class, which as the name suggests can handle big integers, including long
.
Upvotes: 2