2017-02-04 74 views
0

美好的一天。我已經檢查了關於同一主題的其他問題。但我似乎不明白爲什麼我的應用程序拋出一個外鍵不匹配錯誤。爲什麼會引發SQL外鍵不匹配

在我的患者表中,我將localUuid聲明爲我的主鍵。

@Column(isPrimaryKey = true, isUnique = true, isNotNullable = true) 
@Expose 
@SerializedName("local_uuid") 
protected String localUuid; 
在我的約會表

,我宣佈patientUuid一個外鍵

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

所以,問題是當我更新列的patientUuid

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

許多感謝的價值和遺憾英語不好

+1

我建議你嘗試在模擬器上運行你的應用程序。只是因爲你可以找到數據庫並檢查它的結構和表格。 列中可能存在拼寫錯誤,或者甚至沒有創建表格。 這個錯誤可能意味着[following](http://stackoverflow.com/a/5208331/3128927) – FiN

+0

你爲什麼引用'Appointment'表中的'localUuid'列?這個專欄是否存在? –

+0

顯示實際的數據庫結構。顯然,你沒有主鍵。 –

回答

0

從你描述的和向我們展示的,沒有列叫Appointment表中的localUuid。但是,有一列patient_Uuid,其中Patient表中引用了localUuid。如此看來您的更新應該是這個樣子:

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

我不知道爲什麼你有外鍵不匹配的錯誤,但是如果你的原始查詢有效不指定任何外鍵,或許這導致在特別的錯誤。

相關問題