【问题标题】:SQL error foreign key constraintSQL错误外键约束
【发布时间】:2011-06-28 12:34:36
【问题描述】:

我现在挣扎了四天,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 无法添加或更新子行:外键约束失败(soiree.invitation,CONSTRAINT invitation_ibfk_1 FOREIGN KEY (invites_id) REFERENCES invitation (id) 删除级联)

我真的需要这方面的帮助,谢谢!

【问题讨论】:

  • 在您尝试上传灯具时是否会出现此错误消息?

标签: symfony1


【解决方案1】:

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

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

【讨论】:

  • 您好,首先感谢您抽出宝贵时间阅读并回答我的帖子。不幸的是,我做了你让我做的改变,但没有任何改变,我仍然得到同样的错误......
  • 确保您有 foreign:id 引用的任何表在该表中都有一个 id。例如在 Groupe_Invites 表上: Soiree: { onDelete: CASCADE, local: soiree_id, foreign: id, alias: Soiree, class: Soiree, refClass: Groupe_invites } 确保 Soiree 表有一个 id,因为您正在尝试引用通过foreign:id
猜你喜欢
  • 2015-04-03
  • 2011-07-17
  • 1970-01-01
  • 1970-01-01
  • 2016-02-01
  • 1970-01-01
  • 2011-06-12
  • 1970-01-01
相关资源
最近更新 更多