簡體   English   中英

幫助理解和修復mysql錯誤消息完整性違規:1452

[英]Help to Understand and fix mysql error message Integrity violation: 1452

順便說一下,我使用的是zendframework,doctrine 1.2和MYSQL

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

問題是我將數據存儲到Regions表中,這些區域的值為[id:AR,name:Test Name,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]

我使用了識別關系而不是非識別關系

區別在哪里?

這是我的解決方案。 問題如上所述。

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

當我創建一個新行時,我也從引用表中給出了FK

我已經成功解決了這個問題。 我使用MySQL Workbench並且關系規范錯誤。 我使用了識別關系而不是非識別關系。 希望這有助於某人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM