0
我使用laravel架構構建和這裏的錯誤是我的代碼...MySQL的SQLSTATE [23000]在laravel
//create links table
Schema::create('links', function($table){
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('domain_id');
$table->string('url');
$table->softDeletes();
$table->timestamps();
});
Schema::table('links', function($table) {
$table->index('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->index('domain_id');
$table->foreign('domain_id')->references('id')->on('domains')->onDelete('cascade')->onUpdate('cascade');
});
}
但我嘗試的東西保存到該表它拋出下面的錯誤...
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`we`.`links`, CONSTRAINT `links_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert into `links` (`updated_at`, `created_at`) values (2014-09-04 17:35:53, 2014-09-04 17:35:53))
請建議如果您需要更多的東西來更好地理解這個,請幫我解決這個問題。
感謝
它實際上更新失敗。 – seoppc 2014-09-04 19:00:14
我猜這個過程的一部分是生成註釋的SQL查詢,它包含在你的錯誤中:「insert into'links'('updated_at','created_at')values(2014-09-04 17:35: 53,2014-09-04 17:35:53)「。堆棧跟蹤在laravel.log中的樣子是什麼? – stakolee 2014-09-04 19:06:41
'1452無法添加或更新子行:外鍵約束失敗('''''''鏈接',CONSTRAINT'links_user_id_foreign' FOREIGN KEY('user_id')REFERENCES'用戶'('ID')ON DELETE CASCADE ON UPDATE CASCADE)(SQL:插入'links'('updated_at','created_at')values(2014-09-04 19:12:57,2014-09-04 19:12:57))' – seoppc 2014-09-04 19:16:32