2011-03-03 102 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从引用表