运行 php artisan 将表从 laravel 应用程序迁移到本地主机数据库时出现的问题

Issues when running php artisan migrate tables from laravel app to localhost database

以下:是我会收到的错误(请注意,如果不是用户 table,它是 failed_jobs 或 reset_password table。大多数问题来自 laravel auto-generated tables。是的,我确实尝试了 PHP artisan migrate: reset, drop the tables from本地主机,我什至删除了数据库本身)

Migrating: 2014_10_12_100000_create_password_resets_table

   Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `password_resets` add index `password_resets_email_index`(`email`))

  at C:\xampp\htdocs\project1\project\seed\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

  1   C:\xampp\htdocs\project1\project\seed\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464
      PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")

  2   C:\xampp\htdocs\project1\project\seed\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464
      PDOStatement::execute()

这就是 database/migration/create_reset_password_table 到目前为止的样子。

class CreatePasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('password_resets');
    }
}

提前感谢您的所有帮助! :)

Laravel 默认排序规则类型已更改为 utf8mb4。

在你的

AppServiceProvider.php

启动方式如下一行

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}