S
S
Soft_touch_plastic2021-03-04 18:16:10
Python
Soft_touch_plastic, 2021-03-04 18:16:10

Why autoincrement increases but new lines in the table do not appear?

Hello, I am using the mysql library in python, making a normal connection. When I try to execute a SELECT query, everything works, but when I execute an INSERT query, the table's auto-increment increases, but no new elements appear in the table.
Table structure:
6040f7d136d4c504526250.png

A method that works great with SELECT queries:

def query(self, db, query, values=False):
        if values:
            cursor = db.cursor(prepared=True)
            cursor.execute(query, values)
        else:
            cursor = db.cursor()
            cursor.execute(query)
        result = []
        for data in cursor:
            result.append(data)
        return result

result2 = self.query(db, 'INSERT INTO admins (user_id, password) VALUES (%s, %s)', [id, new_password])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2021-03-04
@Soft_touch_plastic

db.commit() must be done
And auto-increment is atomic - it grows even if the transaction is rolled back

R
Rsa97, 2021-03-04
@Rsa97

Text values ​​in the query must be enclosed in quotation marks.
Auto-increment reserves the next value before each INSERT attempt. If the attempt fails, then the reserved value is not returned, and a gap appears in the list of auto-increment field values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question