要添加列,但即使存在迁移类也未找到 [英] Want to add column but migration class is not found even It exists

查看:91
本文介绍了要添加列,但即使存在迁移类也未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Laravel.

I am learning Laravel.

这是我的迁移文件代码.

Here is my migration file code.

class CreatePostTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('post', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned(); // i want to add this column after adding this line i runs the command refresh but it shows below errors.
            $table->string('title');
            $table->text('body');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('post');
    }
}

现在我有一个问题,每当我在PhpStorm的终端中运行此命令时:

Now I have a problem that whenever I run this command in terminal in PhpStorm:

php artisan migrate:refresh

它显示以下错误:

PHP致命错误:在第335行的C:\ xampp \ htdocs \ cms \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Migrations \ Migrator.php中找不到类'AddIsAdminColumnToPostTable'

PHP Fatal error: Class 'AddIsAdminColumnToPostTable' not found in C:\xampp\htdocs\cms\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php on line 335

Symfony \ Component \ Debug \ Exception \ FatalErrorException] 找不到"AddIsAdminColumnToPostTable"类

Symfony\Component\Debug\Exception\FatalErrorException] Class 'AddIsAdminColumnToPostTable' not found

我在终端​​此处的解决方案中尝试过composer dump-autoload,但它无法正常工作.我也使用了rollback命令,但是仍然有问题.

I tried composer dump-autoload in terminal solution from here but it's not working. I also used rollback command but still having issue.

如何制作refresh这个?

推荐答案

Artisan会根据文件名查找迁移.如果希望将其称为其他名称:回滚,删除迁移,进行新的迁移.或者,更改文件名以使其与类名完全匹配.

Artisan looks for migrations based on the file name. If you want it to be called something else: rollback, delete the migration, make a new migration. Or, change the file name to exactly match the class name.

为您,尝试更改

class CreatePostTable extends Migration

class AddIsAdminColumnToPostTable extends Migration

这篇关于要添加列,但即使存在迁移类也未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆