Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 禁止删除在其他表laravel中使用的行_Sql_Laravel 5.4 - Fatal编程技术网

Sql 禁止删除在其他表laravel中使用的行

Sql 禁止删除在其他表laravel中使用的行,sql,laravel-5.4,Sql,Laravel 5.4,所以我有两张桌子: Schema::create('groups', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->integer('course_id'); $table->timestamp('start_date')->nullable(

所以我有两张桌子:

Schema::create('groups', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->integer('course_id');
            $table->timestamp('start_date')->nullable();
            $table->timestamp('end_date')->nullable();
            $table->timestamps();
        });

Schema::create('courses', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('description')->nullable();
            $table->timestamps();
        });
编辑课程时,我有一个删除它的功能。但是,我希望有一个功能,它不允许删除课程行,因为它的id在groups表中使用。这应该在SQL中完成,还是laravel有一些神奇的功能?如何正确显示错误


谢谢。

您使用的是哪种数据库管理系统?大多数人都支持“强制引用完整性”,这正是我认为您需要的。@JeffUK,我使用mariadb@JRLambert谢谢这就是我要找的。