jeudi 10 mars 2016

Android UNIQUE constraint failed: recepit.R_id

I have table Logs and Recepit. And I created third table called logs_belongs_to_Recepit. So I wana store id-s of each this table in that third one so i could display all logs by recepit.

Question:
Why am I getting error UNIQUE constraint failed?

here is my code in which i create tables.

public static final String TABLE_LOGS = "Logs";
    public static final String TABLE_RECEPIT = "recepit";
    public static final String TABLE_LOGS_BELONGS_TO_RECEPIT = "logs_recepits";
String CREATE_LOGS_TABLE = "CREATE TABLE " + TABLE_LOGS + " (" +
                KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                KEY_CREATED_AT + " TIMESTAMP DEFAULT CURRENT_TIMESTAMP,"+
                KEY_PLATENUMBER + " TEXT, " +
                KEY_SORT + " TEXT, "+
                KEY_GRADE+ " TEXT, "+
                KEY_DIAMETER + " INTEGER, " +
                KEY_LENGTH + " INTEGER);";

String CREATE_RECEPITS_TABLE = "CREATE TABLE " + TABLE_RECEPIT + " (" +
                RECEPIT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                RECEPIT_PLACE + " TEXT, " + RECEPIT_SHIPPING + " TEXT, " +
                RECEPIT_WAREHOUSE + " TEXT, " + RECEPIT_CARRIER + " TEXT, " +
                RECEPIT_LICENCE + " TEXT, " + RECEPIT_DRIVER + " TEXT, " +
                RECEPIT_CUSTOMER + " TEXT, " + RECEPIT_DEST_WAREHOUSE + " TEXT, " +
                RECEPIT_EMPLOYEE + " TEXT, " +
                RECEPIT_CREATED_AT + " TIMESTAMP DEFAULT CURRENT_TIMESTAMP);";

String CREATE_LOGS_BELONGS_TO_RECEPITS_TABLE = "CREATE TABLE " + TABLE_LOGS_BELONGS_TO_RECEPIT + " (" + RECEPIT_ID + " INTEGER, " +
                KEY_ID + " INTEGER, FOREIGN KEY("+ RECEPIT_ID +") REFERENCES "+ TABLE_RECEPIT + "("+ RECEPIT_ID +"), FOREIGN KEY("+ KEY_ID +") REFERENCES "+ TABLE_LOGS +"("+ KEY_ID +"));";

Aucun commentaire:

Enregistrer un commentaire