【问题标题】:getthng a throwback error when trying to rollback migrations in laravel尝试在 laravel 中回滚迁移时出现回退错误
【发布时间】:2016-10-18 00:37:46
【问题描述】:

我正在尝试 migrate:rollback 用户表并收到此错误:

[Symfony\Component\Debug\Exception\FatalThrowableError]  
  Class 'AddSortable' not found   

当我迁移:重置时,我得到同样的错误,当我尝试迁移时,我得到

  [Illuminate\Database\QueryException]                                                                  
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create t  
  able `users` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `  
  email` varchar(255) not null, `password` varchar(255) not null, `remember_token` varchar(100) null,   
  `created_at` timestamp null, `updated_at` timestamp null) default character set utf8 collate utf8_un  
  icode_ci)                                                                                             



  [PDOException]                                                                         
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

这是我的用户表

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

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

这是database.php中mysql的代码

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

任何帮助将不胜感激!

【问题讨论】:

    标签: php mysql laravel migration


    【解决方案1】:

    您可能在之前的迁移中设置了 users 表。

    另一方面,我不得不说我似乎总是在回滚时中断我的迁移。我只好手动删除数据库中的表,然后再次运行artisan migrate

    它远非最佳,但我还没有找到它发生的原因。时不时地在谷歌上搜索了半年多,但似乎没有找到合适的答案。

    编辑:再次搜索互联网给出了我提出的相同建议。也尝试像其他答案所说的那样运行composer update dump-autoloadCheck here for some info on the Laravel forums

    【讨论】:

      【解决方案2】:

      在我看来,您删除或重命名了名为 AddSortable

      的迁移

      运行 composer dump-autoload 让它重新制作类缓存并尝试再次运行回滚。

      【讨论】:

      • 我尝试过,但它仍然给我这个错误 [Symfony\Component\Debug\Exception\FatalThrowableError] Class 'AddSortable' not found not sure where AddSortable 甚至来自
      • 检查您的迁移表,看看您是否可以在其中找到该类。如果它在那里,不幸的是您在某个时候使用该迁移类名称进行了迁移,并且需要像其他评论者所说的那样手动删除表。
      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 2017-03-08
      • 1970-01-01
      • 2019-02-14
      • 2015-07-10
      • 1970-01-01
      • 2021-07-01
      • 2017-04-18
      相关资源
      最近更新 更多