0

This code still stores duplicate KEY_NAME. How can i solve it ?

String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "(" + KEY_ID + " integer primary key autoincrement, " + KEY_NAME + " text not null unique " +")";

public void addContact(Contact contact) {
   SQLiteDatabase db = this.getWritableDatabase();
   ContentValues values = new ContentValues();
   values.put(KEY_NAME, contact.getName());
   db.insert(TABLE_CONTACTS, null, values);
   db.close();
}
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
Hridoy_089
  • 300
  • 3
  • 10
  • 1
    Have you added the `unique` constraint only after running an earlier version of your app on the same device? You can e.g. uninstall the app to remove the old version of your database file. – laalto Jan 05 '18 at 10:36
  • it works , thanks . – Hridoy_089 Jan 05 '18 at 11:17

0 Answers0