0

Good day. i already checked the other question regarding the same topic. but i cant seem to understand why my app is throwing a Foreign key Mismatch error.

in my Patient table, i declared localUuid as my Primary key.

@Column(isPrimaryKey = true, isUnique = true, isNotNullable = true)
@Expose
@SerializedName("local_uuid")
protected String localUuid;

in my Appointment table, i declared patientUuid a Foreign key

@NOrm.Column(isForeignKey = true, referenceTable = "Patient",   referenceColumn = "localUuid", isNotNullable = true)
@Expose
@SerializedName("patient_Uuid")
protected String patientUuid;

so the Problem comes when i update the value of the Column patientUuid

db.execSQL("UPDATE Appointment SET clinicUuid = '289f0c31-a8e3-4906-8ab2-c39e2dad368e' 
WHERE localUuid ='a1584d2c-50df-46d6-86f7-6b753697116a'");

many thanks and sorry for bad english

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Emil Heraña
  • 82
  • 10
  • 1
    I would suggest you to try running your app on emulator. Just because so you can find the database and check its structure and tables. There could be an typo mistake with the column or even you didn't create the table. That error can mean [following](http://stackoverflow.com/a/5208331/3128927) – sharp Feb 04 '17 at 10:22
  • Why are you referring to the `localUuid` column in the `Appointment` table? Does this column even exist? – Tim Biegeleisen Feb 04 '17 at 10:22
  • Show the actual database structure. Apparently, you do not have a primary key. – CL. Feb 04 '17 at 11:19

1 Answers1

0

From what you described and showed us, there is no column called localUuid in the Appointment table. However, there is a column called patient_Uuid which references a column called localUuid in the Patient table. So it seems your update should look something like this:

db.execSQL("UPDATE Appointment SET clinicUuid = '289f0c31-a8e3-4906-8ab2-c39e2dad368e'
            WHERE patient_Uuid ='a1584d2c-50df-46d6-86f7-6b753697116a'");

I'm not sure why you got the foreign key mismatch error, but if your original query effectively is not specifying any foreign key, maybe this resulted in that particular error.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360