2011-06-28 248 views
0

我挣扎了四天,现在sql外键约束失败,我reaaly不知道为什么。我已经阅读了关于该主题的所有信息,看起来一切都很好。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,约束invitation_ibfk_1外键(invites_id)参考文献invitationid)ON DELETE CASCADE)

我REA在这个问题上需要帮助,谢谢!

+0

此错误信息是否会出现申请这在有意义的表:

ID:{真实类型:整数,初级:真正​​的,自动增量}? – Tom

回答

0

我通常会将ID列添加到我的表中。当你试图上传灯具

+0

嗨,首先感谢您花时间阅读和回复我的文章。不幸的是,我做了你告诉我做的改变,没有任何改变,我仍然得到相同的错误... – Lambivist

+0

请确保你有一个外国人的任何表:id参考在该表中有一个id。例如在Groupe_Invites表上:Soiree:{onDelete:CASCADE,local:soiree_id,foreign:id,别名:Soiree,class:Soiree,refClass:Groupe_invites}确保Soriee表有一个id,因为你试图引用它通过foreign:id – daSn0wie