Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 422 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UNIQUE constraint failed: sqlite database : android

#11
My mistake was, I tried to fill `ID` column though it was already defined as `INTEGER PRIMARY KEY AUTOINCREMENT`

Reply

#12
*For Kotlin model classes*

If you're assigning a **default value** to the primary key like this:

```kotlin
data class MyModel(
@PrimaryKey(autoGenerate = true) val id: Int = defaultValue
)
```

**Make sure default value is `0` for `Long` and `Int` types.**

---

From the `autoGenerate` comment:

> If the field type is `long` or `int` (or its TypeConverter converts it to a `long` or `int`), `Insert` methods treat `0` as **not-set** while inserting the item.

In my case, I used `-1` as the defaultValue and this error was occurring.
Reply

#13
Guys i had the same problem and i cleared my local database from android settings and a clear run the app, that is work for me. Maybe you made a little change in db and you forgot.
Reply

#14
I solved it by didn't insert the primary key manually when it is autoGenerate, this means that instead of putting value in the insert method for id, try to create an instance of entity class and use it in the insert method
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through