我通過Jobeet學習了Symfony和Doctrine。我想在JobeetJob中添加關係。 這是原文: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/03如何在Doctrine中創建關係
我這樣做:
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
JobeetCategorya:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
categorya_id: { type: integer, notnull: true }
type: { type: string(255) }
(...)
expires_at: { type: timestamp, notnull: true }
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
JobeetCategorya: { onDelete: CASCADE, local: categorya_id, foreign: id, foreignAlias: JobeetJobsa }
當我這樣做:
php symfony doctrine:build --all --and-load
我有錯誤
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
jobeet
.jobeet_job
, CONSTRAINTjobeet_job_categorya_id_jobeet_categorya_id
FOREIGN KEY (categorya_id
) REFERENCESjobeet_categorya
(id
) ON DELETE CASCADE)
爲什麼呢?
帕特里克,你應該把你的標題作爲一個問題來制定,因爲Jobeet是symfony/doctrine,並且把它放在那裏。這有助於其他人發現他們可能回答的問題。只是一個建議:'如何在Doctrine中建立關係?' – hakre 2011-06-12 15:54:11
當你遇到錯誤時,你會怎麼做? – hakre 2011-06-12 15:54:43
我這樣做:php symfony doctrine:build --all - and-load – 2011-06-12 16:11:54