我創建了一個與sfGuardUser模型有關係的sfGuardUserProfile模型。然後我定義另一個與sfGuardUserProfile關係的模型。我在創建數據庫時沒有遇到任何錯誤,但是當我嘗試將數據保存到我的操作文件中的sfGuardUserProfile時,出現此錯誤:Symfony + Doctrine - 可以將兩個以上的表格/模型鏈接在一起?
SQLSTATE [23000]:完整性約束違規:1452無法添加或更新子行:外鍵約束失敗
在我的schema.yml中,我將關係定義爲一對一。
我不知道爲什麼這會失敗。 Doctrine是否僅僅不支持向已經存在關係的模型添加新的關係?
編輯 這裏是我的schema.yml:
sfGuardUserProfile:
tableName: sf_guard_user_profile
columns:
sf_guard_user_id: { type: integer(4) }
email: { type: string(255) }
relations:
User:
class: sfGuardUser
type: one
foreignType: one
onDelete: CASCADE
local: sf_guard_user_id
foreign: id
foreignAlias: Profile
FacebookAccount:
tableName: facebook_account
columns:
user_id: { type: integer(4) }
page_id: { type: integer }
relations:
sfGuardUserProfile:
type: one
foreignType: one
class: sfGuardUserProfile
local: user_id
foreign: sf_guard_user_id
onDelete: CASCADE
foreignAlias: FacebookAccount
我遇到的錯誤當我這樣做:
$profile = $this->getUser()->getProfile();
$profile->setEmail('[email protected]');
$profile->save();
生成的SQL:
INSERT INTO sf_guard_user_profile (sf_guard_user_id, email) VALUES (?, ?) - (1, [email protected])
確切錯誤:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`site`.`sf_guard_user_profile`, CONSTRAINT `sf_guard_user_profile_sf_guard_user_id_facebook_account_user_id` FOREIGN KEY (`sf_guard_user_id`) REFERENCES `facebook_account` (`user_id`))
你能告訴的定義和查詢你嘗試用生成的執行(也許SQL)? – 2010-02-11 19:00:40
我已編輯以顯示更多細節 – 2010-02-11 19:57:26