0
我使用symfony的1.4,我的架構如下:爲什麼我得到一個約束錯誤?
Auditor:
columns:
id:
type: integer
autoincrement: true
primary: true
username:
type: string(255)
password:
type: string(255)
fullname:
type: string(255)
is_auditor:
type: integer
is_manager:
type: integer
is_director:
type: integer
Task:
columns:
id:
type: integer
autoincrement: true
primary: true
client:
type: string(255)
start_date:
type: date
end_date:
type: date
assigned_by:
type: string(255)
comments:
type: string
status:
type: integer
relations:
Auditors:
foreignAlias: Tasks
class: Auditor
refClass: AuditorTask
AuditorTask:
columns:
id:
type: integer
autoincrement: true
primary: true
auditor_id:
type: integer
primary: true
task_id:
type: integer
primary: true
relations:
Auditor:
foreignAlias: AuditorTasks
Task:
foreignAlias: AuditorTasks
Expense:
columns:
id:
type: integer
autoincrement: true
primary: true
auditor_task_id:
type: integer
date:
type: date
hours_spent:
type: integer
transport_cost:
type: float
remarks:
type: string
relations:
AuditorTask:
foreignAlias: Expenses
當我嘗試創建一個新的任務,我得到以下錯誤:
SQLSTATE [HY000]:常規錯誤: 1452無法添加或更新子行,外鍵約束失敗
審計和任務有一個多對多的關係(ehr
auditor_task
,約束auditor_task_id_expense_auditor_task_id
外鍵(id
)參考文獻expense
(auditor_task_id
)。)臀部。從而結交表。審計師可以對任務發表意見,因此我使用審計任務和審計任務之間的一對多關係。
有什麼想法?
確定這裏是從調試的痕跡。
1 Info sfPatternRouting Match route "default" (/:module/:action/*) for /task/create with parameters array ('module' => 'task', 'action' => 'create',)
2 Info sfFilterChain Executing filter "sfRenderingFilter"
3 Info sfFilterChain Executing filter "sfExecutionFilter"
4 Info taskActions Call "taskActions->executeCreate()"
5 Info Doctrine_Connection_Mysql exec : SET NAMES 'UTF8' -()
6 Info Doctrine_Connection_Statement execute : SELECT COUNT(*) AS num_results FROM auditor a WHERE a.id IN (?) - (1)
7 Info Doctrine_Connection_Statement execute : SELECT a.id AS a__id, a.username AS a__username, a.password AS a__password, a.fullname AS a__fullname, a.is_auditor AS a__is_auditor, a.is_manager AS a__is_manager, a.is_director AS a__is_director FROM auditor a WHERE (a.id IN (?)) - (1)
8 Info Doctrine_Connection_Statement execute : INSERT INTO task (client, start_date, end_date, assigned_by, comments, status) VALUES (?, ?, ?, ?, ?, ?) - (Falcon Limited, 2005-01-02, 2005-02-02, mr manager one, asap., 0)
9 Info Doctrine_Connection_Statement execute : INSERT INTO auditor_task (auditor_id, task_id) VALUES (?, ?) - (1, 1)
10 Error Doctrine_Connection_Mysql_Exception SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`ehr`.`auditor_task`, CONSTRAINT `auditor_task_id_expense_auditor_task_id` FOREIGN KEY (`id`) REFERENCES `expense` (`auditor_task_id`))
11 Info sfWebResponse Send status "HTTP/1.1 500 Internal Server Error"
12 Info sfWebResponse Send header "Content-Type: text/html; charset=utf-8"
你得到一個堆棧跟蹤?如果是的話,請張貼它,如果沒有嘗試得到一個... – greg0ire 2010-08-17 19:47:50
你的schema.yml似乎破了:應該有更多的換行符(例如關係之前)。你有什麼作爲task_id爲新創建的任務(答案應該是1)。並嘗試獲得更多的聲譽(例如通過填寫個人資料),以便發表評論。 – greg0ire 2010-08-20 16:57:03
嘿,對不起,我沒有注意到它是如此破碎。只有當我把它粘貼在這裏時纔會破損。否則它不會在我的實際文件中損壞。有人告訴我,我不應該在交接表中有ID,但是它是一對多關係所必需的。 – han 2010-08-22 09:17:37