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谢谢这就是我要找的。