foreign key for sql lite


Last Updated:

  1. cowboy

    cowboy New Member This Topic's Starter

    Joined:
    Mar 22, 2010
    Messages:
    4
    Likes Received:
    0
    Hello every one! I have some problem with my SQL request. I am trying to create tables like this :
    Code (Text):
    1.  myDB.execSQL("CREATE TABLE IF NOT EXISTS "
    2.               + categories
    3.               + " (category_id PRIMARY KEY,parent_id INT,FOREIGN KEY(parent_id) REFERENCES categories(category_id),name text,amount float);");
    4.       myDB.execSQL("CREATE TABLE IF NOT EXISTS "
    5.               + accounts
    6.               + " (account_id PRIMARY KEY, name text);");
    It is compiled ok. But then i tried to run it on emulator the app has dropped with error :
    APPLICATION HAS STOPPED UNEXPECTADLY.

    And i ve finded error occur in the FOREIGN KEY. WHAT problem?
     

    Advertisement
  2. kiranuday43

    kiranuday43 Member

    Joined:
    Mar 3, 2010
    Messages:
    20
    Likes Received:
    0
    FOREIGN_KEY is used between the two tables,,,I found that you are referencing the attribute in the same table,,,and two attributes name should be same,,
     

Share This Page

Loading...