【发布时间】:2017-03-31 00:28:34
【问题描述】:
我与数据库中的 category_id 列有外来关系,但在删除时出现错误。 这是我的删除代码:
public function destroy($id)
{
$category = Category::find($id);
$category->delete();
Session::flash('success', 'The category was successfully deleted.');
return redirect()->route('categories.index');
}
我看到的错误是:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`fitilicious`.`products`, CONSTRAINT `products_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)) (SQL: delete from `categories` where `id` = 2)
请帮忙。
【问题讨论】:
标签: php mysql laravel laravel-5.2