为什么我不能使用生成的名称进行迁移?

时间:2018-04-19 10:37:27

标签: laravel laravel-5 terminal artisan laravel-5.6

2018_04_19_095256_create_admins_table.php,这就是这个名字 当我运行命令“php artisan make:migration ...”

时生成

当我运行命令“php artisan migrate”时,它不显示在我的数据库中

但是当我更改它运行的迁移名称时。我换了  迁移名称"2018_04_19_095256_create_admins_table.php"到  "2014_04_19_095256_create_admins_table.php"

此外,"2014_10_12_100000_create_password_resets_table.php"未在我的数据库中显示

我有什么方法可以使用生成名称进行迁移吗?

迁移文件代码:

Migration table created successfully.

   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 `admins` add unique `admins_email_unique`(`email`))

  at C:\xampp\htdocs\century\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

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

  2   PDOStatement::execute()
      C:\xampp\htdocs\century\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458

  Please use the argument -v to see more details.

1 个答案:

答案 0 :(得分:0)

进入AppServiceProvider,它将位于App / Providers,并按照以下内容进行编辑

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

注意我们添加了Schema的用法,并在启动函数中添加了Schema :: defaultStringLength。这将删除错误。