How to Solve Mysql missing ERROR 1265: Data truncated for

Problem encountered: error 1265 when Python inserts data to MySQL

I saw some posts on the Internet. They were all about the insufficient length of the table field and the type discrepancy. I checked the data I wanted to insert and found that it was really a data problem

user = users(id='0009', email='小9', password='小小', admin=2, name='小小', image='小小', created_at=22)

The data you want to insert is as above, but after initialization, the data saved in userargs is not saved according to (ID, email, password, admin, name, image, created)_ At) the data in this order is [name, ID, email, created]_ At, image, password, admin, etc

def __init__(self, **kwargs):
    userargs = []
    # print "lenofkwargs", len(kwargs)
    if len(kwargs) >= 0:
        for attr, value in kwargs.iteritems():
            setattr(self, attr, value)
            userargs.append(value)

Although we don’t know the reason, we have established the corresponding dict by using the setattr function__ init__ Function can be processed as follows:

self.usertuple = (self.id, self.email, self.password, self.admin, self.name, self.image, self.created_at)

This way, there will be no errors in the insertion

Similar Posts: