SQLAlchemy truncating Column = (Integer)

strange problem here:

I have a mirrored SQL alchemy class that looks like this:

class Install(Base):
    __tablename__ = 'install'
    id = Column(Integer, primary_key=True)
    ip_address = Column(Integer)

I will convert the string representation ("1.2.3.4") to int using:

struct.unpack('!L', socket.inet_aton(ip_address))[0]

This works, I made sure that it converts IP correctly. However, when I look at the database, most of them are truncated to "2147483647"

2147483647 I can’t find out how to stop this truncation, I know that MySQL can handle this, why does SQLAlchemy do this with my integers?

Thanks in advance!

+3
source share
1 answer

Fixed!

MySQL: , INT, mysql.MSInteger(unsigned = True):

from sqlalchemy.databases import mysql
[..]
class Install(Base):
    __tablename__ = 'install'
    id = Column(Integer, primary_key=True)
    ip_address = Column(mysql.MSInteger(unsigned=True))
+2

Source: https://habr.com/ru/post/1755774/


All Articles