Laravel 进阶教程,数据损坏,删除用户直接失败?

我在学习laravel进阶教程中,在数据损坏的这个部分的时候,发生了后台删除用户的时候,直接失败操作,用户并没有被删除的情况?
错误图片
file
代码的部分

class AddReferences extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::table('topics',function (Blueprint $table){

            //当user_id对应的users表数据被删除时,删除词条
            $table->foreign('user_id')->references('id')->on('users')->onDetele('cascade');
        });

        Schema::table('replies', function (Blueprint $table){

          // 当 user_id 对应的 users 表数据被删除时,删除此条数据
          $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
          // 当 topic_id 对应的 topics 表数据被删除时,删除此条数据
          $table->foreign('topic_id')->references('id')->on('topics')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::table('topics', function (Blueprint $table) {
            // 移除外键约束
            $table->dropForeign(['user_id']);
        });
        Schema::table('replies', function (Blueprint $table) {
            $table->dropForeign(['user_id']);
            $table->dropForeign(['topic_id']);
        });
    }
}
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

第一个onDelete打错了! 问题解决!

6年前 评论
讨论数量: 4

有沒有刪除失敗的錯誤訊息可以參考

6年前 评论

"SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (larabbs.topics, CONSTRAINT topics_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id)) (SQL: delete from users where id in (10))"

6年前 评论

第一个onDelete打错了! 问题解决!

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!