【问题标题】:Help to Understand and fix mysql error message Integrity violation: 1452帮助理解和修复 mysql 错误消息完整性违规:1452
【发布时间】:2011-03-03 14:39:12
【问题描述】:

顺便说一句,我正在使用 zendframework、doctrine 1.2 和 MYSQL

//错误 消息:SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(gepm2.Regions,约束Regions_id_Districts_regions_id外键(id)参考Districtsregions_id))

问题是我将数据存储到 Regions 表中,这些区域的值 [ 身份证: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]

【问题讨论】:

    标签: mysql


    【解决方案1】:

    我使用了识别关系而不是非识别关系

    区别在哪里?

    这是我的解决方案。问题如上。

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

    当我创建一个新行时,我还会从引用的表中给出 FK

    【讨论】:

      【解决方案2】:

      我已经设法弄清楚了。我使用了 MySQL Workbench 并弄错了关系规范。我使用了识别关系而不是非识别关系。希望这对某人有所帮助。

      【讨论】:

        猜你喜欢
        • 2012-09-19
        • 2012-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-15
        • 2012-01-01
        • 1970-01-01
        相关资源
        最近更新 更多