【问题标题】:Why cant I use the generated name for a migration?为什么我不能使用生成的名称进行迁移?
【发布时间】:2018-09-29 20:00:06
【问题描述】:

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.

【问题讨论】:

  • 粘贴您的迁移文件代码。
  • 你检查迁移表吗?如果“2018_04_19_095256_create_admins_table.php”或表中的任何名称已迁移。
  • 检查你的 .env 文件,这是你应该有你的数据库连接信息的地方,旁边确保显示你遇到的任何错误,Laravel 应该在命令行中显示一些错误,当它无法迁移。
  • @VolkanYılmaz 没有像“2018_04_19_095256_create_admins_table.php”这样的表,但是当我将其更改为“2014_04_19_095256_create_admins_table.php”时它可以工作。我创建了几乎 3 个相同的工匠命令来进行迁移,但也不起作用
  • @killstreet 没有错误“DB_CONNECTION=mysql [DB_HOST=127.0.0.1], [DB_PORT=3306], [DB_DATABASE=Century], [DB_USERNAME=root], [DB_PASSWORD="]。我在 .env 中的数据库连接。 3 表显示在我的数据库中,但 reset_password 没有显示。这 3 个是 :"[migration], [admins], [user] " 表

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


【解决方案1】:

进入位于 App/Providers 的 AppServiceProvider 并进行如下编辑

<?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 的使用,并在 boot 函数中添加了 Schema::defaultStringLength。这将消除错误。

【讨论】:

  • 在 AppServiceProvider.php 第 16 行:找不到类 'App\Providers\Schema'
猜你喜欢
  • 2020-11-10
  • 2020-08-14
  • 2021-10-06
  • 2017-10-08
  • 2014-07-13
  • 2013-07-09
  • 2012-02-26
  • 2019-08-23
  • 1970-01-01
相关资源
最近更新 更多