提交后遇到错误的" php工匠迁移:新鲜" cmd。
<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
sqlstate [42000]:语法错误或访问违规:指定密钥的1071键太长;最大密钥长度为767字节(SQL:Alter Table users
添加唯一users_email_unique
(email
((
来自此链接:https://laravel-news.com/laravel-5-4-key-too-long-eror
对于那些运行Mariadb或以上版本的MySQL的人,您可能会击中此事试图运行迁移时的错误
如《迁移指南》中概述的修复此操作的所有所要做的就是编辑您的appserviceprovider.php文件和启动方法内部设置一个默认字符串长度:
use IlluminateSupportFacadesSchema;
public function boot()
{
Schema::defaultStringLength(191);
}
之后,一切都应该正常工作。
请注意,根据安德鲁·科斯特(Andrew Koster(的评论,这可能只是用于旧版代码的解决方案。您可能希望研究最新项目的不同解决方案。
编辑:该软件包的fyi ... v4,在迁移中添加了一些唯一的索引,如果您使用MySQL 8.0,则需要125而不是191。(Mariadb不需要任何一个(。
根据官方Laravel 7.x
文档,您可以很容易地解决此问题。
更新您的/app/Providers/AppServiceProvider.php
文件以包含:
use IlluminateSupportFacadesSchema;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}