Laravel,从迁移中创建MySQL触发器
我已经从迁移中创建了MySQL存储过程,它工作得很好。
DB::unprepared('
CREATE PROCEDURE sp_Create_Default_Task_1(IN _kid_id INT)
BEGIN
INSERT INTO tasks (kid_id, name) VALUES (_kid_id, \'daily\');
END'
);
此后,我尝试使用相同的代码创建MySQL触发器
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTrigger extends Migration {
public function up()
{
DB::unprepared('
CREATE TRIGGER tr_Task_Default AFTER INSERT ON `kids` FOR EACH ROW
INSERT INTO tasks (`kid_id`, `name`) VALUES (NEW.id, \'Default\');
');
}
public function down()
{
DB::unprepared('DROP TRIGGER `tr_User_Default_Member_Role`');
}
}
但它在我运行后返回错误php artisan migrate
{"error":{"type":
"Symfony\\Component\\Debug\\Exception\\FatalErrorException",
"message":"Class 'CreateTriggers' not found",
"file":"C:\\xampp\\htdocs\\dev03\\vendor\\laravel\\framework
\\src\\Illuminate\\Database\\Migrations\\Migrator.php",
"line":301}}
问题:哪里出错了?