【问题标题】:Laravel homestead PDOExceptionLaravel 宅基地 PDOException
【发布时间】:2019-06-15 03:53:05
【问题描述】:

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

我有 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.

谁能帮帮我?

【问题讨论】:

  • 邮政编码和错误信息,不是图片。
  • 能否显示迁移文件contact_event
  • 您的反应表中有 3 个增量列。将 user_idevent_id 改为 bigInteger。
  • 检查您的迁移以查找contact_event 表。确保只有一个 $table->increments()

标签: php laravel pdo homestead


【解决方案1】:

如果您检查错误跟踪:

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

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

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

从数据库中删除用户表,同时从迁移表中删除用户条目。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-24
    • 2016-04-17
    • 2015-12-09
    • 2015-02-28
    • 1970-01-01
    • 2016-07-31
    • 2018-04-17
    • 1970-01-01
    相关资源
    最近更新 更多