在Laravel 5.4上使用php artisan make:auth迁移错误
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl e users add unique users_email_unique(email))
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
1-进入/config/database.php,找到这些行
'mysql' => [
...,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
...,
'engine' => null,
]
并更改为:
'mysql' => [
...,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
...,
'engine' => 'InnoDB',
]
2-运行php artisan config:cache重新配置laravel
3-删除数据库中现有的表,然后再次运行php artisan migrate
我只是把这个答案加在这里,因为这对我来说是最快的解决方法。只需要将默认的数据库引擎设置为'InnoDB'
/ config / database.php
'mysql' => [
...,
...,
'engine' => 'InnoDB',
]
然后运行PHP artisan config:cache来清除和刷新配置缓存
编辑:
这里找到的答案可能解释了这一事件背后的原因
1-进入/config/database.php,找到这些行
'mysql' => [
...,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
...,
'engine' => null,
]
并更改为:
'mysql' => [
...,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
...,
'engine' => 'InnoDB',
]
2-运行php artisan config:cache重新配置laravel
3-删除数据库中现有的表,然后再次运行php artisan migrate
如果您运行“php artisan migrate”时出现此错误。你可以这样修改你想要更新的表:
DB::statement('ALTER TABLE table_name ROW_FORMAT = DYNAMIC;');
在迁移脚本中。例子:
class MyMigration extends Migration {
/**
* Run the migrations.
*/
public function up()
{
DB::statement('ALTER TABLE table_name ROW_FORMAT = DYNAMIC;');
Schema::table('table_name', function ($table) {
//....
});
}
/**
* Undo the migrations.
*/
public function down()
{
//....
}
}
然后再次运行php artisan migrate