学说,symfony 1.4:如何解决此“完整性约束违规”问题?
我已经在 schema.yml 中定义了这个实体,
Jobsearch:
tableName: jobsearch
columns:
seeker_id:
primary: true
type: integer
notnull: true
autoincrement: false
empmode:
type: string(50)
pensum:
type: integer
active:
type: boolean
relations:
Privateaccount:
local: seeker_id
foreign: id
alias: seeker
它有一个外键引用,
Privateaccount:
tableName: privateaccount
columns:
id:
primary: true
unique: true
type: integer
notnull: true
autoincrement: true
firstname:
type: string(255)
lastname:
type: string(255)
inheritance:
extends: sfGuardUser
type: column_aggregation
keyField: type
keyValue: Privateaccount
我出于测试目的做了一个 symfony 操作,它应该将 Jobsearch 保存到数据库:
public function executeTest(sfWebRequest $request)
{
$test = new Jobsearch();
$test->setSeeker( $this->getUser()->getGuardUser() ) ; // set the user that is logged in
$test->save();
}
$test->save()
结果出现此错误:
SQLSTATE[23000]:违反完整性约束:1451 无法删除或 更新父行:外键约束失败 (
test2
.sf_guard_user_profile
,约束sf_guard_user_profile_user_id_sf_guard_user_id
外键 (user_id
) 参考sf_guard_user
(id
) ON DELETE CASCADE)
我不明白为什么外键约束失败。
是什么导致了这个错误?
编辑:如果我将 seeker_id
中的 primary
更改为 false
,它确实有效。但我希望外键成为主键。如果可能的话,我该如何使其发挥作用?
I have defined this entity in schema.yml
Jobsearch:
tableName: jobsearch
columns:
seeker_id:
primary: true
type: integer
notnull: true
autoincrement: false
empmode:
type: string(50)
pensum:
type: integer
active:
type: boolean
relations:
Privateaccount:
local: seeker_id
foreign: id
alias: seeker
it has a foreign key reference to
Privateaccount:
tableName: privateaccount
columns:
id:
primary: true
unique: true
type: integer
notnull: true
autoincrement: true
firstname:
type: string(255)
lastname:
type: string(255)
inheritance:
extends: sfGuardUser
type: column_aggregation
keyField: type
keyValue: Privateaccount
I made a symfony action for testing purpose, it is supposed to save a Jobsearch to db:
public function executeTest(sfWebRequest $request)
{
$test = new Jobsearch();
$test->setSeeker( $this->getUser()->getGuardUser() ) ; // set the user that is logged in
$test->save();
}
$test->save()
results in this error:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or
update a parent row: a foreign key constraint fails
(test2
.sf_guard_user_profile
, CONSTRAINTsf_guard_user_profile_user_id_sf_guard_user_id
FOREIGN KEY
(user_id
) REFERENCESsf_guard_user
(id
) ON DELETE CASCADE)
I don't see why the foreign key constraint is failing.
What has caused the error?
EDIT: If I change primary
to false
in seeker_id
, it does work. But I want the Foreign Key to be the Primary Key. If possible, how do I make that work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 schema.yml 更改为
,
Doctrine 默认创建 id 字段。不要声明它。
最后,它应该可以工作。
Try changing the schema.yml to
and
Doctrine creates the id field by default. Don't declare it.
Finally, it should work.