SQL错误外键约束

时间:2011-06-28 12:34:37

标签: symfony1

我正在苦苦挣扎四天,现在有一个SQL外键约束失败了,我真的不知道为什么。我已经阅读了关于这个主题的所有内容,似乎一切都很好。

这是我的schema.yml

Soiree:
  actAs: { Timestampable: ~ }
  columns:
  titre:        { type: string(255), notnull: true }
  description:  { type: blob(), notnull: true }
  adresse: { type: string(255), notnull: true, unique: true }
  code_postal: {type: integer, notnull: true }
  ville: {type: string(255), notnull:true}
  date: {type: timestamp, notnull: true }
  type_id: {type: integer, notnull: true }
  flyer: {type: string(255), notnull:true }
  is_visible: { type: boolean, notnull:true, default:0 }
  user_id: {type:integer, notnull: true}
relations:
  sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id, foreignAlias: Users} 
  Type: {onDelete: CASCADE, local: type_id, foreign: id, alias: Types, class: Type, refClass: Soiree}  

Type:
  columns:
    titre: {type: string(255), notnull: true}

Invitation:
  actAs: { Timestampable: ~ }
  columns:
    titre:        { type: string(255), notnull: true }
    description:  { type: blob(), notnull: true }
    image:      { type: string(255), notnull: true }
    is_sent: {type: boolean, notnull:true, default:0}
    adresse:         { type: string(255) }
    code_postal:          { type: string(255) }
    code_QR: {type: string(255), notnull: true }
    invites_id: {type:integer }
    user_id: {type:integer, notnull: true}
    groupe_invites_id : {type:integer, notnull: true }
    soiree_id: {type:integer, notnull:true}
  relations:
    Invites: { onDelete: CASCADE, local: invites_id, foreign: id, alias: invite, class: Invites, refClass: Invitation } 
    Groupe_invites: { onDelete: CASCADE, local: groupe_invites_id, foreign: id, alias: invit_groupes, class: Groupe_invites, refClass: Invitation } 
    sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id, foreignAlias: Users} 
    Soiree: { onDelete: CASCADE, local: soiree_id, foreign: id, alias :Soirees, class: Soiree, refClass: Invitation } 



Groupe_invites:
  actAs: { Timestampable: ~ }
  columns:
    titre:       { type: string(255), notnull: true }
    description:     { type: string(255), notnull: true, unique: true }
    invites_id:     { type: integer, notnull: true }
    soiree_id: { type: integer }
    user_id: {type:integer, notnull: true}
  relations:
    Invites:
      onDelete: CASCADE
      local: invites_id
      foreign: id
      alias: invites
      class: Invites
      refClass: Groupe_invites
    sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id, foreignAlias: Users} 
    Soiree: { onDelete: CASCADE, local: soiree_id, foreign: id, alias: Soiree, class: Soiree, refClass: Groupe_invites } 

Invites:
  columns:
    nom:  { type: string(255), notnull: true }
    prenom: { type: string(255), notnull: true }
    age: {type: integer, notnull : true }
    email: {type: string(255), notnull: true, unique: true }
    adresse: {type: blob(), notnull: true }
    telephone: {type: integer(255), notnull: true }
    soiree_id: {type: integer, notnull: true }
    user_id: {type:integer, notnull: true}
  relations:
    sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id, foreignAlias: Users} 
    Soiree: { onDelete: CASCADE, local: soiree_id, foreign: id, alias: Soiree_invite, class: Soiree, refClass: Invites } 

Organisateur:
   actAs: {Timestampable: ~ }
   columns:
    nom: {type: string(255), notnull: true }
    prenom: {type: string(255), notnull: true }
    age: {type: integer, notnull: true }
    description: {type: blob(), notnull: true }
    photo: {type: string(255), notnull: true }
    user_id: {type:integer, notnull: true}
  relations:
    sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id, foreignAlias: Users} 


Image:
columns:
    titre: {type: string(255), notnull: true }
    description: {type: string(255), notnull: true }
    lien: {type: string(255)}
    album_id: {type: integer}
    user_id: {type: integer}
relations:
    Album: {onDelete: CASCADE, local: album_id, foreign: id, alias: Albums, class:Album, refClass:Image}
    sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id} 


Album:
columns:
    titre: {type: string(255), notnull: true }
    description: {type: blob(), notnull: true }
    user_id: {type:integer, notnull: true}
relations:
    sfGuardUser: {onDelete: CASCADE, local: user_id, foreign: id} 

我的错误类型为:

SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败(soireeinvitation,CONSTRAINT invitation_ibfk_1 FOREIGN KEY({{ 1}})参考invites_idinvitation)ON DELETE CASCADE)

我真的需要帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

我通常会将id列添加到我的表中。将它应用于有意义的表格:

id:{type:integer,primary:true,autoincrement:true}