MySqlBuilder :: defaultStringLength()

时间:2018-10-24 10:56:40

标签: php laravel symfony-1.4

尽管有几次尝试,但我还是遇到了defaultStringLength()问题。我向你解释我的程序。

在文件夹数据库中-> 2018_10_24_103651_create_devis_table.php我知道了:

<?php

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

class CreateDevisTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('devis', function (Blueprint $table) {
            $table->increments('id');
            $table->string('firstname');
            $table->string('lastname');
            $table->string('email');
            $table->string('phone');
            $table->string('start_adress');
            $table->string('end_adress');
            $table->text('remarks');
            $table->timestamps();
        });
    }

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

然后,我必须更改文件AppServiceProvider.php

这是我的修改

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(255);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

之后,我在下一个php artisan migrate上运行命令,并且得到类似错误消息的结果->调用未定义的方法Illuminate \ Database \ Schema \ MySqlBuilder :: defaultStringLength()

请问您有个主意吗? 我预先感谢您的回答。

1 个答案:

答案 0 :(得分:0)

defaultStringLength,这是在Laravel 5.4中引入的

您可以更新Laravel版本

您将长度指定为$table->string('coumname', 255);。您不能将长度指定为255