【问题标题】:MySqlBuilder::defaultStringLength()MySqlBuilder::defaultStringLength()
【发布时间】:2018-10-24 10:56:40
【问题描述】:

尽管进行了多次搜索,但我还是遇到了 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()

请问你有什么想法吗? 提前感谢您的回答。

【问题讨论】:

  • Schema::defaultStringLength(191); used @anais_stem
  • Jignesh Joisar:即使是问题我也不明白为什么它不起作用???
  • 你使用的是什么版本的 laravel
  • @anais_stem 阅读这篇文章laravel-news.com/laravel-5-4-key-too-long-error
  • @Shaielndra Gupta:我有 5.3.8 版

标签: php laravel symfony-1.4


【解决方案1】:

defaultStringLength 这是在 Laravel 5.4 中引入的

你可以更新 Laravel 版本

您将长度指定为$table-&gt;string('coumname', 255); 您不能指定超过255

【讨论】:

  • 我正在尝试您的第二个解决方案,但它不起作用: public function up(){ Schema::create('biodatas', function (Blueprint $table) { $table->increments(' id'); $table->string('test'); $table->string('coumname', 255); $table->timestamps(); });
  • 如果是,你是否仍然收到错误,告诉我你正在犯什么错误
  • @Shaielndra Gupta :哦,对不起!哇哇哇哇哇哇哇哇!!!我删除了 Schema::defaultStringLength(255);在文件 AppServiceProvider.php
  • @Shaielndra Gupta : 我也想更新我的版本
  • 是的,你可以新版本的 laravel 有新的功能,不要忘记也投票
猜你喜欢
  • 2017-06-25
  • 1970-01-01
  • 2018-07-10
  • 2018-06-14
  • 2019-09-28
相关资源
最近更新 更多