1

I have seen some other questions about this, but none of the answers really seemed to work for my code. I'm getting a 'SQLiteConstraintException: error code 19: constraint failed' error when I try to insert into my DB. Here is the code for the insert operation

@Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("Create table " + DATA_TABLE + "(" + KEY_ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_NAME
                + " TEXT NOT NULL," + KEY_Type + " TEXT);");
                }
    public static  void insert_data(String name, String Type) {

    mDB = DBHelper.getWritableDatabase();
    ContentValues iv = new ContentValues();
    iv.put(KEY_NAME, name);
    iv.put(KEY_Type, Type);

    mDB.insert(DATA_TABLE, null, iv);

}

In my activity I am inserting the values into the database

   DB.insert_data("All value", "All artist");//my constrain error points here
4

0 回答 0