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