首页 文章

Laravel - 运行迁移时未找到类

提问于
浏览
1

我想运行迁移以将设施列添加到我的图像表,但它会带来此错误

Already: No such file or directory
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating optimized autoload files

Illuminate \ Foundation \ ComposerScripts :: postAutoloadDump @php artisan package:discover发现包:fideloper / proxy发现包:nunomaduro / collision发现包:laravel / tinker发现包:uxweb / sweet-alert发现包:yajra / laravel-datatables- oracle包清单生成成功 .

Symfony\Component\Debug\Exception\FatalThrowableError  : Class          'AddFacilitiesToImagesNew' not found

 at     /var/www/roomhub/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:418
414|     public function resolve($file)
415|     {
416|         $class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));
417|

418 |返回新的$ class; 419 | } 420 | 421 | / ** 422 | *获取给定路径中的所有迁移文件 .

Exception trace:

 1       Illuminate\Database\Migrations\Migrator::resolve("2018_05_26_085447_add_faciliti    es_to_images_new")
         /var/www/roomhub/vendor/laravel/framework/src/Illuminate/Database/Migrations/Mig    rator.php:168

 2       Illuminate\Database\Migrations\Migrator::runUp("/var/www/roomhub/database/migrations/2018_05_26_085447_add_facilities_to_images_new.php")
  /var/www/roomhub/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:146

 Please use the argument -v to see more details.

THIS IS THE MIGRATION FILE

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFacilitiesToImagesNewTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::table('images_new', function (Blueprint $table) {
        $table->string('facilities');
    });
}
/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('images_new', function (Blueprint $table) {
        $table->dropColumn('facilities');
    });
}
}

请问是什么导致错误

1 回答

  • 1

    按照这一思路, Class AddFacilitiesToImagesNew 无法解决 .

    在错误回溯中,打印了一个从文件名确定类名的行 .

    $class = Str::studly(implode('_', array_slice(explode('_', $file), 4)));
    

    严格地说,您的类必须在迁移文件中命名为 AddFacilitiesToImagesNew .

    检查 2018_05_26_085447_add_facilities_to_images_new.php 中的迁移类是否正确命名为 AddFacilitiesToImagesNew .

    Edit :还有一件事,迁移不需要命名空间 . 如果这个需要出于某种原因,请确保它已添加到您的作曲家并且您确实转储了自动加载文件 .

相关问题