I have created MySQL stored procedure from migration and it works just fine.
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'
);
Hereafter I tried to do the same to create MySQL trigger with following code
<?php
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
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`');
}
}
But it returns error after I run 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}}
Question: What is going wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…