title: Getting UNIQUE constraint failed: tbl_data.id (Sqlite code 1555 SQLITE_CONSTRAINT_PRIMARYKEY) error in android studio room
body: <p>I'm getting this error while i have initialize the id as primary key and i added the unique attribute.</p>
  <p>Data class code :</p>
  <pre><code>    @Entity(tableName = &quot;tbl_data&quot; , indices = {@Index(value = {&quot;id&quot;},
      unique = true)})
      public class Data {
      @PrimaryKey
      private Integer id ;
      private Integer year;
      private Double dowry;
  
  public Data(Integer id,Integer year, Double dowry) {
      this.id = id;
      this.year = year;
      this.dowry = dowry;
  }
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public int getYear() {
      return year;
  }
  public void setYear(int year) {
      this.year = year;
  }
  public Double getDowry() {
      return dowry;
  }
  public void setDowry(Double dowry) {
      this.dowry = dowry;
  }
  </code></pre>
  <p>Data Base Class code :</p>
  <pre><code>@Database(version = 1 , exportSchema = false , entities = {Data.class} )
  public abstract class AppDatabase extends RoomDatabase {
  private static AppDatabase appDatabase;
  
  public static AppDatabase getAppDatabase(Context context) {
      if (appDatabase == null)
          appDatabase = Room.databaseBuilder(context.getApplicationContext(),
  AppDatabase.class,
                  &quot;db_app&quot;)
                  .allowMainThreadQueries().fallbackToDestructiveMigration()
                  .build();
          return appDatabase;
      }
  
      public abstract DataDao getDataDao();
  }
  </code></pre>
  <p>and main activity code :</p>
  <pre><code>    db = AppDatabase.getAppDatabase(this);
      dataDao = db.getDataDao();
  
      dataDao.insertC(new Data(1,1315, 0.004 ), new Data(2,1316, 0.005), new Data(3,1317,  0.006), new Data(4,1318, 0.007));
  </code></pre>
  <p>and full error in logat :</p>
  <blockquote>
  <p>2021-11-07 12:20:45.070 24994-24994/com.mohajer.kitset2 E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.mohajer.kitset2, PID: 24994
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mohajer.kitset2/com.mohajer.kitset2.MainActivity}: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: tbl_data.id (Sqlite code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), (OS error - 2:No such file or directory)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
  at android.os.Handler.dispatchMessage(Handler.java:112)
  at android.os.Looper.loop(Looper.java:216)
  at android.app.ActivityThread.main(ActivityThread.java:7625)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
  Caused by: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: tbl_data.id (Sqlite code 1555 SQLITE_CONSTRAINT_PRIMARYKEY), (OS error - 2:No such file or directory)
  at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
  at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:841)
  at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:803)
  at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
  at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
  at androidx.room.EntityInsertionAdapter.insertAndReturnIdsArrayBox(EntityInsertionAdapter.java:199)
  at com.mohajer.kitset2.DataDao_Impl.insertC(DataDao_Impl.java:50)
  at com.mohajer.kitset2.MainActivity.onCreate(MainActivity.java:36)
  at android.app.Activity.performCreate(Activity.java:7458)
  at android.app.Activity.performCreate(Activity.java:7448)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614) 
  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86) 
  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199) 
  at android.os.Handler.dispatchMessage(Handler.java:112) 
  at android.os.Looper.loop(Looper.java:216) 
  at android.app.ActivityThread.main(ActivityThread.java:7625) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) </p>
  </blockquote>