我正在使用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');
}
}
任何想法我做错了什么?
答案 0 :(得分:1)
您可以回滚迁移,然后再次运行:
php artisan migrate:rollback
然后:
php artisan migrate
在您的情况下, 注意这将删除表格中的所有数据,因为它会删除users
和password
提醒,然后重新创建。
另一种方法是创建新的迁移:
php artisan migrate:make users_add_soft_deletes
把它放在那里:
Schema::table('users', function ($table) {
$table->softDeletes();
});
并运行php artisan migrate
以应用新迁移