1

私はlaravelを使用しており、別の移行を行おうとしていますが、テーブルが既に存在するため、次のエラーがスローされています:

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

移行ファイルに次の行を追加しました。

$table->softDeletes();

これは完全なファイルです:

<?php

use Illuminate\Database\Migrations\Migration;

class ConfideSetupUsersTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        // Creates the users table
        Schema::create('users', function ($table) {
            $table->increments('id');
            $table->string('firstname');
            $table->string('lastname');
            $table->string('username')->unique();
            $table->string('email')->unique();
            $table->string('password');
            $table->string('confirmation_code');
            $table->string('remember_token')->nullable();
            $table->softDeletes();
            $table->boolean('confirmed')->default(false);
            $table->timestamps();
        });

        // Creates password reminders table
        Schema::create('password_reminders', function ($table) {
            $table->string('email');
            $table->string('token');
            $table->timestamp('created_at');
        });
    }

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

私が間違っていることはありますか?

4

1 に答える 1

2

移行をロールバックしてから、再度実行できます。

php artisan migrate:rollback

その後:

php artisan migrate

あなたの場合、テーブルからすべてのデータが削除されuserspasswordリマインダーが作成されてから再作成されるため、注意してください。

別の方法は、新しい移行を作成することです。

php artisan migrate:make users_add_soft_deletes

これをそこに入れます:

Schema::table('users', function ($table) {
    $table->softDeletes();
});

そして実行php artisan migrateして、新しい移行を適用します

于 2015-02-07T21:12:27.243 に答える