views:

23

answers:

1

Hi guys, weird issue here:

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

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

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

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

This does work, I've made sure it's converting IPs right. However, when I look at the database, most of them have been truncated to "2147483647"

2147483647 I can't find out how to stop this truncation, I know that MySQL can handle this, why is SQLAlchemy doing this to my integers?

Thanks in advance!

+1  A: 

Fixed it!

For MySQL: Make sure you are using unsigned INTs, and then use the mysql.MSInteger(unsigned=True) type:

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