SQLite3 UNIQUE constraint failed error
You have set list_id to be the primary key on the list table, which means that value must be unique for each record. Trying to insert multiple records with the same list_id table is therefore causing the error.
The issue is the same for the item table.
SQLite IntegrityError: UNIQUE constraint failed:
The UNIQUE
clause of your table's declaration states that every row's combination of player_id
, map_id
, and runID
must be unique. You are getting this error because there is already a row in the jumptimes
table withplayer_id = 13
, map_id = 34
, and runID = 0
.
Here is a simple SQLFiddle reproducing the error. The "constraint" the error is talking about is the UNIQUE clause, and if you could see the full error, it would be the same as the one you're getting.
UNIQUE constraint failed: sqlite database : android
Your code probably violates primary key's uniqueness constraint on a KEY_ID
field.
Two possible solutions are:
- Make sure that your
EventData.getId()
returns unique values per object. For now, I don't see you pass any identifier to its constructor and perhaps all the events are inserted with the sameid
value. - If you don't care about generating ids by yourself, you can add
AUTOINCREMENT
setting to yourKEY_ID
column definition. This wayKEY_ID
field will be filled automatically and each row will have its own, unique value. Once there, don't forget to remove addingKEY_ID
toContentValues
by yourself.
sqlite3.IntegrityError: UNIQUE constraint failed | When using bulk adding many-to-many relation
You should probably check if the reason why you are having those errors is because of duplicate data. If that's the case, I think the ignore_conflicts
parameter of bulk_create
can solve your problem. It will save every valid entry and ignore those who have duplicate conflict.
Check the doc:
https://docs.djangoproject.com/en/3.2/ref/models/querysets/#django.db.models.query.QuerySet.bulk_create
Related Topics
SQL Combine Two Columns in Select Statement
How to Compare Software Versions Using SQL Server
Normalizing Accented Characters in MySQL Queries
How to Create Daylight Savings Time Start and End Function in SQL Server
How to Generate Date Series to Occupy Absent Dates in Google Biqquery
SQL Error: Ora-02291: Integrity Constraint
Select Rows with Maximum Column Value Group by Another Column
SQL Not Displaying Null Values on a Not Equals Query
Ora-01861: Literal Does Not Match Format String
How to Create a Table Alias in MySQL
Safest Way to Get Last Record Id from a Table
How to Dynamically Use Tg_Table_Name in Postgresql 8.2
Shredding Xml from Execution Plans
Why Does the Following Join Increase the Query Time Significantly
Inner Join VS Multiple Table Names in "From"
How to Insert New Row to Database with Auto_Increment Column Without Specifying Column Names