【发布时间】:2011-11-26 01:08:40
【问题描述】:
我已经在 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 保存到 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() 导致此错误:
SQLSTATE[23000]:违反完整性约束:1451 无法删除或 更新父行:外键约束失败 (
test2.sf_guard_user_profile, 约束sf_guard_user_profile_user_id_sf_guard_user_id外键 (user_id) 参考sf_guard_user(id) 删除级联)
我不明白为什么外键约束会失败。
是什么导致了错误?
编辑:如果我将seeker_id 中的primary 更改为false,它确实有效。但我希望外键成为主键。如果可能的话,我该怎么做?
【问题讨论】:
标签: mysql orm symfony1 doctrine foreign-keys