Symfony插入SQL错误 - 外键约束失败

时间:2011-07-13 10:13:43

标签: php mysql symfony1 symfony-1.4 propel

我正在使用fixture来为我的symfony项目生成数据,但由于某种原因,以下错误不断被抛出:

  

无法执行INSERT语句。 [包装:SQLSTATE [23000]:   完整性约束违规:1452无法添加或更新子行:   外键约束失败(meetingmeeting_attendance,   约束meeting_attendance_FK_1外键(meeting_id)   参考meeting_meetingsid))]

我正在寻找错误发生的原因,我正在使用Symfony 1.4,带有propel和MySQL数据库。


会议架构和考勤架构如下所示,http://pastebin.com/HZhaqWSN

的完整副本
  meeting_meetings:
    id: ~
    owner_id: { type: integer, foreignTable: sf_guard_user_profile, foreignReference: user_id, required: true }
    group_id: { type: integer, foreignTable: meeting_groups, foreignReference: id }
    name: { type: varchar, required: true, default: Meeting } 
    completed: { type: boolean, required: true, default: 0 } 
    location: { type: varchar, required: true,  default: Unknown }
    start: { type: integer, required: true }
    length: { type: integer, required: true, default: 60 }
    created_at: ~
    updated_at: ~

  meeting_attendance:
    id: ~
    meeting_id: { type: integer, foreignTable: meeting_meetings, foreignReference: id, required: true }
    user_id: { type: integer, foreignTable: sf_guard_user_profile, foreignReference: user_id, required: true }
    invited: { type: boolean, required: true, default: 0 }
    attending: { type: boolean, required: true, default: 0 }
    apolgies: { type: boolean, required: true, default: 0 }
    attended: { type: boolean, required: true, default: 0 }
    apolgies_comment: { type: varchar(255) }

03_meetings.yml如下

MeetingMeetings:
  PezMeeting:
    owner_id: Pezmc
    completed: 0
    location: Awesome Room
    start: 1310059022
    length: 60

和09_attendance.yml如下:

MeetingAttendance:
  MeetingAttendance1:
    meeting_id: PezMeeting
    user_id: Pezmc
    invited: 1
    attending: 1
    apolgies: 0
    attended: 0
    apolgies_comment: None

我的两个灯具都是使用PHP随机生成的,但我已将它们更改为上面的内容以尝试找到此错误!

我认为我一定忽略了一些简单的事情,但我一直试图调试这个超过一个小时,我的智慧结束了!

有谁知道导致此错误的原因或解决方法?

非常感谢你的时间,


编辑:有人建议将所有内容放在一个文件中,我已经完成了这个并使用php运行该文件(以确切了解推送的内容)。它仍然会出现同样的错误:

MeetingMeetings:
  PezMeeting:
    owner_id: Pezmc
    completed: 0
    location: Awesome Room
    start: 1310059022
    length: 60

MeetingItems:
  Item1:
    Value: VfH0qXxGV4Ylb ZtRm DKkDE9dTzlWR z Nm TnNhxVPvZO eOn IM5 v ETOl v 4 xsA7HexNwzB YDvz I uay Sjm3rbAu iaiZIPGv l0oNSFCG To

MeetingAgendas:
  Agenda1:
    MeetingId: PezMeeting
    ItemId: Item1

MeetingActions:
  Action1:
    ItemId: Item1
    MeetingId: PezMeeting
    Due: 1310705295
    Start: 1310358321
    Completed: 1

MeetingAttendance:
  MeetingAttendance1:
    meeting_id: PezMeeting
    user_id: Pezmc
    invited: 1
    attending: 1
    apolgies: 0
    attended: 0

仍在:

Unable to execute INSERT statement. [wrapped: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`meeting`.`meeting_agendas`, CONSTRAINT `meeting_agendas_FK_1` FOREIGN KEY (`meeting_id`) REFERENCES `meeting_meetings` (`id`))]  

编辑2:表的生成SQL在这里:http://pastebin.com/XQmM3k7S(下面的一些表)DROP TABLE IF EXISTS meeting_meetings;

CREATE TABLE `meeting_meetings`
(
    `id` INTEGER  NOT NULL AUTO_INCREMENT,
    `owner_id` INTEGER  NOT NULL,
    `group_id` INTEGER,
    `name` VARCHAR(255) default 'Meeting' NOT NULL,
    `completed` TINYINT default 0 NOT NULL,
    `location` VARCHAR(255) default 'Unknown' NOT NULL,
    `start` INTEGER  NOT NULL,
    `length` INTEGER default 60 NOT NULL,
    `created_at` DATETIME,
    `updated_at` DATETIME,
    PRIMARY KEY (`id`),
    INDEX `meeting_meetings_FI_1` (`owner_id`),
    CONSTRAINT `meeting_meetings_FK_1`
        FOREIGN KEY (`owner_id`)
        REFERENCES `sf_guard_user_profile` (`user_id`),
    INDEX `meeting_meetings_FI_2` (`group_id`),
    CONSTRAINT `meeting_meetings_FK_2`
        FOREIGN KEY (`group_id`)
        REFERENCES `meeting_groups` (`id`)
)Type=InnoDB;

3 个答案:

答案 0 :(得分:1)

此灯具必须位于同一文本文档中以帮助保存!

答案 1 :(得分:0)

此灯具必须位于同一个文件中。我的意思是来自03_meetings.yml和09_attendance.yml的灯具

我希望这会有用。

答案 2 :(得分:0)

在config / ProjectConfiguration.class.php中尝试此操作。然后在数据加载后将其注释掉。

class ProjectConfiguration extends sfProjectConfiguration
{
    public function setup()
    {
        // ...
    }

    public function configureDoctrine(Doctrine_Manager $manager)
    {
        $manager->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
    } 
}