php连接成功创建表失败,php – Laravel 5.6:表创建失败

我是Laravel的新手,我正在尝试使用Schemafaçade创建表格.我用命令创建迁移文件

php artisan make:migration create_products_define_standards_table --create=products_define_standards

这是文件:

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');

}

}

它确实具有与默认CreateUsersTable几乎相同的内容,但是当我运行php artisan migrate时,它会创建:

>用户表(默认)

>迁移表(默认)

但不是:

> password_resets’表(默认)

> products_define_standards’表(自定义)

我试过php artisan migrate:fresh但我得到了相同的日志:

Dropped all tables successfully.

Migration table created successfully.

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

at /home/whatever/whatever.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664

660: // If an exception occurs when attempting to run a query, we'll format the error

661: // message to include the bindings with SQL, which will make this exception a

662: // lot more helpful to the developer instead of just the database's errors.

663: catch (Exception $e) {

664: throw new QueryException(

665: $query, $this->prepareBindings($bindings), $e

666: );

667: }

668:

669: return $result;

Exception trace:

1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")

/home/whatever/whatever.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 458

2 PDOStatement::execute()

/home/whatever/whatever.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php : 458

我找到了this answer,我也运行了composer dumpauto但结果是一样的.

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

解决方法:

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

use Illuminate\Support\Facades\Schema;

public function boot()

{

Schema::defaultStringLength(191);

}

标签:php,laravel,database-migration,laravel-5,laravel-5-6

来源: https://codeday.me/bug/20190717/1486439.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值