title: Error in creation of database table in Android using SQL
body: <pre><code> I am trying to make database table using primary key and foreign key. My first table `Categ` contains fields `catgoryId` as primary key and second table `Pers` contains `categoryId` as foreign key.
  </code></pre>
  
  <p>First creation of table is working fine while second is giving error                         that unable to insert data in <code>Person</code> table .</p>
  
  <p>Code is :</p>
  
  <pre><code>  public void onCreate(SQLiteDatabase db) {
         // if any table missing then recreate all tables (can be done             dynamically)
          if(!isTableExist(db, categ)||!isTableExist(db, pers)){
  
          db.execSQL("DROP TABLE IF EXISTS "+categ);
           db.execSQL("DROP TABLE IF EXISTS "+pers);
  
          db.execSQL("create table "+categ+"(categoryId INTEGER PRIMARY KEY autoincrement, name text, isApproved integer ,isDeleted integer, createdDate       text, modifiedDate text)");
  
          db.execSQL("create table "+pers+" (personId INTEGER PRIMARY KEY autoincrement, name text, photo text, biography text,categoryId      integer,isApproved integer, isDeleted integer, createdDate text, modifiedDate     text,FOREIGN KEY(categoryId) REFERENCES categ(categId))");
         }
     }  
  
  }
  </code></pre>
  
  <p>I have created Table by calling updateAllTables Method.
  UpdateAllTables is defined in this way:</p>
  
  <pre><code>public boolean updateAllTables(Context context){
      onCreate(this.getReadableDatabase());
      CDataTransition datatransition = new CDataTransition(context);
      JSONObject jObj = datatransition.getAllTables();
      try {
          JSONArray category = jObj.getJSONArray("categories");
          insertCategories(category);
  
          JSONArray person = jObj.getJSONArray("persons");
          insertPersons(person);
          return true;
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }       
      return false;
  }
  </code></pre>
  
  <p>The methods used above( insertCategoriers and insertPerson) are defined in this way:</p>
  
  <pre><code>public void insertCategories(JSONArray jsArr){
       for (int i = 0; i &lt; jsArr.length(); i++) {
          try {
              JSONObject category = jsArr.getJSONObject(i);
              ContentValues cv = new ContentValues();
                    cv.put("categoryId",Integer.parseInt(category.getString("categoryId")));
              cv.put("name",category.getString("name"));
              cv.put("isApproved",Integer.parseInt(category.getString("isApproved")));
              cv.put("isDeleted",Integer.parseInt(category.getString("isDeleted")));
              cv.put("createdDate",category.getString("createdDate"));
              cv.put("modifiedDate",category.getString("modifiedDate"));
  
              insertData(categ, cv);
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }           
      }
  }
  
  public void insertPersons(JSONArray jsArr){
      for (int i = 0; i &lt; jsArr.length(); i++) {
          try {
              JSONObject person = jsArr.getJSONObject(i);
              ContentValues cv = new ContentValues();
              cv.put("personId",Integer.parseInt(person.getString("personId")));
              cv.put("name",person.getString("name"));
              cv.put("photo",person.getString("photo"));
              cv.put("biography",person.getString("biography"));
              cv.put("categoryId",Integer.parseInt(person.getString("categoryId")));
              cv.put("isApproved",Integer.parseInt(person.getString("isApproved")));
                cv.put("isDeleted",Integer.parseInt(person.getString("isDeleted")));
              cv.put("createdDate",person.getString("createdDate"));
              cv.put("modifiedDate",person.getString("modifiedDate"));
  
              insertData(pers, cv);
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }           
      }
  }
  </code></pre>