Laravel homestead PDOException

Laravel homestead PDOException

所以我正在尝试迁移此代码:

我有 6 个类似(或类似)的迁移:

反应

class Reaction extends Migration
{
    public function up()
    {
        Schema::create('reaction', function (Blueprint $table) {
            $table->increments('reaction_id');
            $table->integer('user_id');
            $table->integer('event_id');
            $table->integer('reaction_type');
            $table->string('comment');
            $table->timestamp('date');
        });
    }


    public function down()
    {
        Schema::drop('reaction');
    }
}

产品

class Products extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->increments('product_id');
            $table->string('name');
            $table->integer('price');
            $table->bigInteger('pieces');
            $table->timestamp('date_added');
        });
    }

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

但是当我输入 php artisan migrate

时出现了这个错误

错误:

vagrant@homestead:~/Code/Laravel$ php artisan migrate
Migrating: 2019_01_21_134236_users

   Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`users_id` int unsigned not null auto_increment primary key, `last_name` varchar(255) not null, `first_name` varchar(255) not null, `email` varchar(255) not null, `password` varchar(255) not null, `statut` int not null, `date_added` timestamp not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at /home/vagrant/Code/Laravel/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[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
      /home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

  2   PDOStatement::execute()
      /home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

  Please use the argument -v to see more details.

谁能帮帮我?

如果检查错误跟踪:

Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table 'users' ...........

这意味着 用户 table 已经存在,所以当您 运行 您的迁移时,它正在尝试创建一个 table已在您的数据库中创建。

注意:别忘了先备份你的数据库

从数据库中删除 用户 table 同时从 migrations table.[=12 中删除用户条目=]

之后,为了 运行 所有未完成的迁移,执行 migrate Artisan 命令:php artisan migrate