0
Can anyone help me in Sqlite query
I created column 'ID' and gave constraint as 'Primary key', While inserting the values for other columns it is throwing an error to pass the value for 'ID'.
12 Antworten
+ 3
Tibor Santa and Calviղ
Thanks for your help
+ 2
Sultan Shaikh you can also manually specify the value of the ID if you want, when you do the insert.
By using AUTOINCREMENT, the database will assign a number to each new row, based on an algorithm.
Now that Calvin has already told you what is the problem, you are only a Google search away from finding out more:
https://www.sqlite.org/autoinc.html
+ 1
Set AUTOINCREMENT to the ID
+ 1
@Calvin, Data type is int then why should we add autoincrement?
+ 1
Tibor Santa I tried with manual entry, but it is allowing me for duplicate ID. I am not getting any error while entering the same ID which I already have.
+ 1
Sultan Shaikh
The primary key does enforce uniqueness.
See sample code here, it's not possible to insert the same ID twice.
https://code.sololearn.com/cZUM385ZGOa3/?ref=app
+ 1
Tibor Santa
Why did you use executemany instead of using execute for INSERT query?
+ 1
It should not make any difference. Executemany has nice syntax to work on a data structure that contains all the relevant fields, and no need to write a loop. I copied and adjusted the example from python standard documentation.
Maybe you have a problem with commit missing? You did not link your own code, so I can only guess. Maybe I shouldn't. :)
+ 1
Sultan Shaikh Check out here how does the Animal table create data with ID auto increment set in Sqlite
https://code.sololearn.com/wT34BpTg8sgH/?ref=app
0
Int data type is not auto increment by default
0
Yes
0
Mia I got the solution