title: SQLiteConstraintException: error code 19: constraint failed -- Android error
body: <p>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. db.insert returns a -1 right now, which leads to the "failed to insert" message.</p>
  
  <p>Here is the the relevant Content Provider code:</p>
  
  <pre><code>public static final String PROVIDER_NAME = "com.oliverapps.provider.DB";
  
  public static final Uri CONTENT_URI = Uri.parse("content://"+ PROVIDER_NAME + "/tasks");
  
  public static final String _ID = "_id";
  public static final String CATEGORY = "category";
  public static final String STORE = "store";
  public static final String DESCRIPTION = "description";
  public static final String DISTANCE = "distance";
  public static final String CHECKED = "checked";
  
  private static final int KEY_CATEGORY = 1;
  private static final int KEY_STORE = 2;
  private static final int KEY_DESCRIPTION = 3;
  private static final int KEY_DISTANCE = 4;
  private static final int KEY_CHECKED = 5;
  
  private static final UriMatcher uriMatcher;
  static{
      uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
      uriMatcher.addURI(PROVIDER_NAME, "category", KEY_CATEGORY);
      uriMatcher.addURI(PROVIDER_NAME, "category/store", KEY_STORE);
      uriMatcher.addURI(PROVIDER_NAME, "category/store/description", KEY_DESCRIPTION);
      uriMatcher.addURI(PROVIDER_NAME, "category/store/description/distance", KEY_DISTANCE);
      uriMatcher.addURI(PROVIDER_NAME, "checked", KEY_CHECKED);
  }
  
  
  //---for database use---
  private SQLiteDatabase tasksDB;
  private static final String DATABASE_NAME = "tasks";
  private static final String DATABASE_TABLE = "tasks" +
          "";
  private static final int DATABASE_VERSION = 1;
  private static final String DATABASE_CREATE =
      "create table " + DATABASE_TABLE +
      " (" + _ID +  " integer primary key autoincrement, " +
      CATEGORY + " text not null, " + STORE + " text not null, " + DESCRIPTION + " text, " +
      DISTANCE + " text not null, " + CHECKED + " text not null);";
  
  private static class DatabaseHelper extends SQLiteOpenHelper{
      DatabaseHelper(Context context){
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db){
          db.execSQL(DATABASE_CREATE);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
          Log.w("Content provider database", "Upgrading database from version " +
                  oldVersion + " to " + newVersion + ", which will destroy all old data");
          db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
          onCreate(db);
      }
  }
  
  
  @Override
  public Uri insert(Uri uri, ContentValues values){
      //---add a new task---
      long rowID = tasksDB.insert(DATABASE_TABLE, "", values);
  
      //---if added successfully---
      if(rowID &gt; 0){
          Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
          getContext().getContentResolver().notifyChange(_uri, null);
          return _uri;
      }
      throw new SQLException("Failed to insert row into " + uri);
  }
  
  @Override
  public boolean onCreate(){
      Context context = getContext();
      DatabaseHelper dbHelper = new DatabaseHelper(context);
      tasksDB = dbHelper.getWritableDatabase();
      return (tasksDB == null)? false:true;
  }
  </code></pre>
  
  <p>Here is the relevant code from the Android Manifest:</p>
  
  <pre><code>    &lt;provider android:name="DBProvider"
          android:authorities="com.oliverapps.provider.DB" /&gt;
  </code></pre>
  
  <p>And here is the relevant code that calls the insert method above:</p>
  
  <pre><code>ContentValues values = new ContentValues();
                  values.put(DBProvider.CATEGORY, category);
                  values.put(DBProvider.STORE, store);
                  values.put(DBProvider.DESCRIPTION, description);
                  values.put(DBProvider.DISTANCE, distance);
  
                  Uri uri = getContentResolver().insert(DBProvider.CONTENT_URI, values);
  </code></pre>
  
  <p>Any clue why this isn't working? This is mostly code from an Android book I have, modified to my own database.</p>