mysql - 帮助理解和修复mysql错误消息完整性违规: 1452

标签 mysql

顺便说一句,我正在使用 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/

相关文章:

mysql - 选择按关键字分组的行,但对每组加权而不是使用 COUNT()

php - 大流量下的网站PHP+MySQL

mysql - 填充至一定数量

php - 将整个 mysql 结果集转储到数组中的最有效方法?

mysql - SQL语句较大问题

mysql - WAMP重装后部分数据库内容消失

mysql - 在数据库中保留小计字段是个坏主意吗

mysql - 如何在 grails 域中捕获毫秒

mysql - 如何在 MySQL 中随机连接表?

mysql无法创建外键