我在schema.yml中定義這個實體學說,symfony的1.4:我如何解決這個「完整性約束違規」
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]: 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)
我不明白爲什麼外鍵約束失敗。
是什麼導致了錯誤?
編輯:如果我更改primary
到false
在seeker_id
,它確實有效。但我希望外鍵成爲主鍵。如果可能的話,我該如何做這項工作?