2011-03-03 24 views
0

順便說一句,我使用zendframework,學說1.2和MYSQL有助於瞭解和修復MySQL錯誤消息的整體性破壞:1452

//錯誤 消息:SQLSTATE [23000]:完整性約束違規:1452不能添加或更新子行:外鍵約束失敗(gepm2Regions,約束Regions_id_Districts_regions_id外鍵(id)參考文獻Districtsregions_id))

事情是我存儲數據到區表,這些區域的值[ ID :AR, 名稱:測試名稱, Countries_id:UK]

enter code here 


##YAML 
Country: 
tableName: Countries 
columns: 
    id: 
    type: string(3) 
    fixed: true 
    primary: true 
    notnull: true 
    name: 
    type: string(45) 
    default: null 
    currency: 
    type: string(3) 
    fixed: true 
    default: null 

Region: 
tableName: Regions 
columns: 
    id: 
    type: string(2) 
    fixed: true 
    primary: true 
    notnull: true 
    name: 
    type: string(45) 
    default: null 
    Countries_id: 
    type: string(3) 
    fixed: true 
    primary: true 
    notnull: true 
    relations: 
    country: 
    class: Country 
    local: Countries_id 
    foreign: id 
    foreignAlias: regions 
    foreignType: many 
    owningSide: true 
indexes: 
    fk_Regions_Countries: 
    fields: [Countries_id] 

District: 
tableName: Districts 
columns: 
    id: 
    type: string(3) 
    fixed: true 
    primary: true 
    notnull: true 
name: 
    type: string(45) 
    default: null 
Regions_id: 
    type: string(2) 
    fixed: true 
    primary: true 
    notnull: true 
relations: 
    region: 
    class: Region 
    local: Regions_id 
    foreign: id 
    foreignAlias: districts 
    foreignType: many 
    owningSide: true 
indexes: 
fk_Districts_Regions1: 
    fields: [Regions_id] 

回答

0

我設法想出解決辦法。我使用了MySQL Workbench,並且弄錯了關係規範。我使用了識別關係而不是非識別關係。希望這可以幫助某人。

2

我用一個確定的關係,而不是一個非識別關係

其中的區別?

這是我的解決方案。問題就像上面那樣。

$offer = $offerTbl->createRow(array('idcandidate'=>14)); 
$offer->save(); 

當我創建一個新的行我也給FK從引用表