繁体   English   中英

在 Laravel 中运行迁移时出错。 给定的闭包没有参数

[英]Error while running migration in Laravel. The given Closure has no parameters

错误详情如下:

给定的闭包没有参数。

在 \vendor\laravel\framework\src\Illuminate\Support\Traits\ReflectsClosures.php:58

54▕ return [$parameter->getName() => Reflector::getParameterClassNames($parameter)];

55▕ })->filter()->values()->all();

56▕

57▕ if (empty($types)) {

58▕ throw new RuntimeException('给定的闭包没有参数。');

59▕}

60▕

61▕ if (isset($types[0]) && empty($types[0])) {

62▕ throw new RuntimeException('给定闭包的第一个参数缺少类型提示。');

1 E:\Projects\BE-\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\ReportableHandler.php:62 Illuminate\Foundation\Exceptions\ReportableHandler::firstClosureParameterTypes(Object(Closure))

2 E:\Projects\BE-DEV\api\v2\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php:234 Illuminate\Foundation\Exceptions\ReportableHandler::handles(Object(RuntimeException))

这是迁移文件。 没有可用的跟踪日志。 做了研究,但找不到 RCA 和解决方案。 任何人都可以帮助解决这个问题。 没有迁移文件有效。 每次迁移都会出现此错误。

 use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateUserProcedure extends Migration { /** * Run the migrations. * * @return void */ public function up() { $procedure = "DROP PROCEDURE IF EXISTS `get_user_from_userid`; CREATE PROCEDURE `get_user_from_userid` (IN idx int) BEGIN SELECT * FROM users WHERE user_id = idx; END;"; \DB::unprepared($procedure); } /** * Reverse the migrations. * * @return void */ public function down() { } }

发生这种情况有几个原因。 一种调试方法将从为什么您的日志文件中没有条目的问题开始。 日志记录发生在异常处理程序( app/Exceptions/Handler.php )中。

父母使用出现在您的错误消息中的ReflectsClosures特征。

在寄存器 function 中,您可以使用闭包调用$this->reportable$this->renderable renderable。 这些闭包需要将 Exception/Throwable 作为参数,并且该参数需要进行类型提示(例如使用Throwable )。

我敢打赌这就是你的错误所在。 您的迁移对我来说看起来不错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM