【问题标题】:Want to add column but migration class is not found even It exists想要添加列但迁移类即使存在也找不到
【发布时间】:2017-04-27 15:32:02
【问题描述】:

我正在学习 Laravel。

这是我的迁移文件代码。

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 的终端中运行此命令时:

php artisan migrate:refresh

它显示以下错误:

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

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

我在终端 solution from here 中尝试了 composer dump-autoload,但它不起作用。我也使用了rollback 命令,但仍然有问题。

refresh怎么可以这样?

【问题讨论】:

  • 你试过从控制台/终端运行它吗?如果结果相同(不起作用),那么这个问题与 PhpStorm 无关。
  • 是的,从终端运行.. 那么问题出在哪里?
  • @LazyOne 那我该怎么做才能解决这个问题?
  • 在这种情况下,这是某种错误配置或与 Laravel 相关的问题——在这方面我无能为力,因为我不知道你的项目。
  • @LazyOne 好的,谢谢,我刚刚解决了我的问题,我删除了迁移文件,然后再次从终端运行命令 create 命令,然后运行它可以工作的刷新命令 :)

标签: php symfony laravel-5 migration phpstorm


【解决方案1】:

Artisan 根据文件名查找迁移。如果您希望它被称为别的东西:回滚,删除迁移,进行新的迁移。或者,将文件名更改为与类名完全匹配。

为你,尝试改变

class CreatePostTable extends Migration

class AddIsAdminColumnToPostTable extends Migration

【讨论】:

  • 但我还有一个名为 AddIsAdminColumnToPostTable 的类,我只显示这个类,因为我想在 post 表中添加列。
猜你喜欢
  • 1970-01-01
  • 2016-07-05
  • 2019-11-10
  • 1970-01-01
  • 2023-01-11
  • 2017-07-25
  • 2015-10-26
  • 2019-11-16
  • 1970-01-01
相关资源
最近更新 更多