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:
- Solution to the error of MySQL: unrecognized service (CentOS)
- MySQL database insert into statement with parameters Error
- MySQL: Starting MySQL….. ERROR! The server quit without updating PID file
- TypeError: list indices must be integers or slices, not str
- How to Solve Python Error : **kwargs and takes 1 positional argument but 2 were given
- MySQL Use innobackupex to backup and recovery error [How to Solve]
- [Solved] pymongo.errors.OperationFailure: Authentication failed.
- Image data type conversion uint8 and double in MATLAB
- Solve the problem of unknown column ‘password’ in ‘field list’ in MySQL
- [Solved] rocky-linux8.5 Install gitea Error: services.server Additional property db is not allowed