S
S
s1veme2020-09-05 08:30:38
Python
s1veme, 2020-09-05 08:30:38

How to format and add data to SQLITE?

There is such a table:

cur.execute("""CREATE TABLE IF NOT EXISTS users(
    id_records INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    id_chat INT, 
    id_user INT,
    username TEXT,
    having_ban INT DEFAULT 0, 
    having_kick INT DEFAULT 0);""")


There is this addition:
more_users = [(1, 1, '1'), (1, 1, '2')]
    cur.executemany("INSERT INTO users VALUES(NULL, ?, ?, ?);", more_users)


But it gives an error that there are 5 fields in the table, and I indicated only 3.
How can I make it so that without transferring there is nothing, it simply sets having_ban = 0 by default, and so on.

Or is it necessary to specify this in the request? Type...
cur.executemany("INSERT INTO users VALUES(NULL, ?, ?, ?, 0, 0);", more_users)


What is the best way to do this?
What would it be, without the transfer of these fields, would it automatically set 0?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Shubin, 2020-09-05
@aleksegolubev

You can specify the specific fields you want to set.

INSERT INTO users (id_chat, id_user, username) VALUES (1, 1, '1');

I recommend learning SQL syntax. It is not complicated, but it will save you a lot of such questions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question