Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.6:表创建失败_Php_Laravel_Laravel 5_Database Migration_Laravel 5.6 - Fatal编程技术网

Php Laravel 5.6:表创建失败

Php Laravel 5.6:表创建失败,php,laravel,laravel-5,database-migration,laravel-5.6,Php,Laravel,Laravel 5,Database Migration,Laravel 5.6,我不熟悉Laravel,我正在尝试使用Schemafaçade创建表。我使用命令创建迁移文件 php artisan make:migration create_products_define_standards_table --create=products_define_standards 以下是文件: <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use

我不熟悉Laravel,我正在尝试使用
Schema
façade创建表。我使用命令创建迁移文件

php artisan make:migration create_products_define_standards_table --create=products_define_standards
以下是文件:

<?php

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

class CreateStandardsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products_define_standards', function (Blueprint $table) {
            $table->increments('id');
            $table->string('code')->unique();
            $table->string('image');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products_define_standards');
    }
}
我找到并运行了composer dumpauto,但结果是一样的


我错过什么了吗?我应该在其他地方注册迁移吗?

编辑
app/Providers
目录中的
AppServiceProvider.php
,并在
boot()
方法中设置默认字符串长度

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
use Illuminate\Support\Facades\Schema;

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

在5.6版中,您应编辑2个文件:

首先

编辑app/Providers目录中的AppServiceProvider.php,并在boot()方法中设置默认字符串长度

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
use Illuminate\Support\Facades\Schema;

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

编辑位于config/database.php目录中的database.php

在mysql配置部分,“引擎”为空,您应该替换为“
InnoDB ROW\u FORMAT=DYNAMIC


希望您喜欢。

这里的工作方法是传递第二个参数,该参数带有键名(短参数):


我想为这个问题提出一个可能更好的解决方案

您不必编辑属于您的Laravel的任何文件。相反,请编辑实际的数据库排序规则和引擎

我猜您正在使用MySQL或MariaDB。使用phpMyAdmin,当您创建空白数据库时,使用utf8mb4\u unicode\u ci(utf8\u unicode\u ci或utf8P\u general\u ci也可以正常工作)

接下来,将默认数据库引擎设置为InnoDB而不是MyISAM(您也可以在phpMyAdmin中的“变量”选项卡下搜索“引擎”来执行此操作)

人们提出的其他解决方案——即编辑database.php使其以任何方式使用InnoDB——具有非常相似的效果。但MySQL/Maria的现代版本无论如何都应该使用InnoDB开箱即用


运行您的迁移,它将执行良好,无需进一步修改。

Great Sapnesh,所有迁移现在都完美运行。所以问题是Laravel没有为
VARCHAR
提供默认字符串的长度,MySQL抛出了错误?@Brigo是的,类似于此。但是如果您想得到详细的解释,请参阅此部分estion@Brigo如果这对你有帮助,请接受答案:)当然,我在等待“锁定时间”到期:)也谢谢你链接到另一个答案