在laravel中执行数据库迁移时报错解决方案:

忘是亡心i 2022-06-02 07:24 442阅读 0赞

" class="reference-link">Laravel5.4 默认使用 utf8mb4 字符,包括支持在数据库存储「表情」。如果你正在运行的 MySQL release 版本低于5.7.7 或 MariaDB release 版本低于10.2.2 ,为了MySQL为它们创建索引,你可能需要手动配置迁移生成的默认字符串长度,你可以通过调用 AppServiceProvider 中的 Schema::defaultStringLength 方法来配置它。 执行Laravel自带的两个migrations报出以下两个错误,但是刷新数据库表依然创建出来了,那么出错的原因应该就是mysql的版本过低 SouthEast

报错的问题就是max key length too long

那么现在只需要在原本的users migrations代码中添加这一行

public function up()
{
Schema::defaultStringLength(191);
Schema::create(‘users’, function (Blueprint $table) {
$table->increments(‘id’);
$table->string(‘name’);
$table->string(‘email’)->unique();
$table->string(‘password’);
$table->rememberToken();
$table->timestamps();
});
}

在执行以下: ok了

E:\xampp\htdocs\laravelAuth>php artisan migrate

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrating: 2018_01_08_015920_create_clients_table
Migrated: 2018_01_08_015920_create_clients_table

发表评论

表情:
评论列表 (有 0 条评论,442人围观)

还没有评论,来说两句吧...

相关阅读