顺便说一句,我正在使用 zendframework、doctrine 1.2 和 MYSQL
//错误
消息:SQLSTATE[23000]:违反完整性约束:1452 无法添加或更新子行:外键约束失败 (gepm2
.Regions
,CONSTRAINT Regions_id_Districts_regions_id
外键 (id
) 引用 地区
(regions_id
))
问题是我将数据存储到区域表中,这些区域的值[ 编号:AR, 名称:测试名称, Country_id:英国]
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]
最佳答案
I used a Identifying Relationship instead of a Non-Identifying Relationship
区别在哪里?
这是我的解决方案。问题如上。
$offer = $offerTbl->createRow(array('idcandidate'=>14));
$offer->save();
当我创建一个新行时,我也会从引用的表中给出 FK
关于mysql - 帮助理解和修复mysql错误消息完整性违规: 1452,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5182149/