Laravel宅基PDOException

问题描述 投票:1回答:1

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

enter image description here

enter image description here

我有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时,我遇到了这个错误

错误:

enter image description here

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.

谁能帮我?

php laravel pdo homestead
1个回答
1
投票

如果您检查错误跟踪:

Illuminate \ Database \ QueryException:SQLSTATE [42S01]:基表或视图已存在:1050表'用户'已存在(SQL:创建表'users'...........

这意味着users表已经存在,因此当您运行迁移时,它会尝试创建已在数据库中创建的表。

注意:不要忘记先备份数据库

从数据库中删除用户表也会从迁移表中删除用户条目。

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

© www.soinside.com 2019 - 2024. All rights reserved.