在用laravel框架进行数据库迁移的时候报错如下
这是由于Laravel 默认使用 utf8mb4 字符, 包括支持在数据库存储「 表情」 。 如果你正在运行的 MySQL release 版本低于5.7.7 或 MariaDB release
版本低于10.2.2 , 为了MySQL为它们创建索引, 你可能需要手动配置迁移生成的默认字符串长度, 你可以通过调用 AppServiceProvider 中的
Schema::defaultStringLength 方法来配置它:
解决办法
E:\phpstudy\phpstudy_pro\WWW\laravel\app\Providers\AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
Schema::defaultStringLength(191);
}
}
//加上默认字符串长度
数据库删了刚才迁移一半的表,然后再次执行php artisan mirgration
PS E:\phpstudy\phpstudy_pro\WWW\laravel> php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (0.01 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (0.01 seconds)
Migrating: 2023_10_26_233021_create_order_table
Migrated: 2023_10_26_233021_create_order_table (0.02 seconds)