【问题标题】:Why does php artisan migrate nothing?为什么 php artisan 什么都不迁移?
【发布时间】:2015-08-04 07:01:42
【问题描述】:

运行“php artisan migrate”什么都不做:没有数据库修改,没有消息(也没有“nothing to migrate”),没有错误。

也没有记录被添加到表迁移中。

以前,“php artisan migrate”命令运行良好。

文件夹 database/migrations 中的一个迁移文件有这样的内容:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class VidsTableEdit14 extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('vids', function(Blueprint $table)
        {
            //
            $table->integer('test');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('vids', function(Blueprint $table)
        {
            //
        });
    }

}

如何让“php artisan migrate”工作?

【问题讨论】:

  • 您能告诉我们运行命令时命令行上显示的内容吗?这些命令也有用吗? php artisan list 和 php artisan help migrate
  • 嗨,php artisan list 和 php artisan 帮助按预期迁移工作:php artisan list 给出了一个列表,并以“Laravel Framework version 5.0.31”开头。
  • php artisan help migrate 输出开头为:"Usage:" 这些命令似乎没有问题
  • 运行 php artisan migrate 时返回什么?只是它成功的标准消息?
  • 只是一个空行 - 没有消息

标签: php laravel migration migrate laravel-artisan


【解决方案1】:

如果迁移突然停止工作,则可能是您的迁移中某处存在语法错误。如果你突然遇到类未找到错误,请怀疑是语法错误。

【讨论】:

    【解决方案2】:

    当我尝试向我的表添加软删除时,我也遇到了同样的情况。

    我创建了迁移并在 Schema::table 函数中输入了“$table->softDelete();”。而不是

    $table->softDeletes();
    

    注意复数形式的“s”,我尝试运行迁移,但没有收到任何错误或消息。我把它改成复数了,它起作用了。

    我注意到你没有记下function()。尝试添加:

    Schema::drop('vids');
    

    然后再次运行迁移。

    【讨论】:

    • 谢谢!。我重新安装了整个 laravel。下次我会试试你的解决方案。
    【解决方案3】:

    错误:

    SQLSTATE[42S01] 
    Migrating: 2014_10_12_000000_create_users_table
    
       Illuminate\Database\QueryException 
    -------------
    [php artisan migrate] 
    

    解决方案:转到:

    app\Http\Providers\AppServiceProvider
    
    import ( use Illuminate\Support\Facades\Schema; ) 
    

    并且,在register() 函数中,插入以下代码:

    public function register()
    {
         Schema::defaultStringLength(191); 
    }
    

    然后运行:

    php artisan migrate:fresh
    

    【讨论】:

    • 欢迎来到 Stack Overflow。由于格式的原因,我很难阅读您的答案,因此我对其进行了编辑,希望能帮助改进它。但是,请检查以确保修改与您的意图一致。
    猜你喜欢
    • 2020-07-08
    • 2015-09-21
    • 2019-02-13
    • 2020-11-10
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    相关资源
    最近更新 更多