我正在尝试向现有表“用户”添加新列。我创建了一个新的迁移“add_privilege_column_to_users_table”。当我尝试运行 php artisan 迁移时,出现“用户”表已存在的错误。我在这里错过了什么吗?
我已经尝试过谷歌搜索和starckoverflow上其他遇到同样问题的人提供的几种方法。但这里的代码都没有帮助我。
class AddPrivilegesColumnToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('privilege_type')->after('remember_token');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
});
}
}
PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
这是我运行 php artisan migrate 时遇到的特定错误。我只是想向该表添加一个新列。
以下是我的迁移状态:
Run? | Migration
No 2014_10_12_000000_create_users_table
No 2014_10_12_100000_create_password_resets_table
No 2019_07_28_071643_add_privileges_column_to_user_table
最佳答案
看起来你回滚得太远了,但是你的users
表没有被删除,因此Laravel在尝试运行迁移时,正在尝试重新创建该表。
如果您转到数据库,您将能够更新迁移以表明它已经执行,从而跳过该批处理。
UPDATE migrations SET batch = 1 WHERE migration = '2014_10_12_000000_create_users_table';
关于php - 尝试为现有表创建列时出现错误用户已存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57239011/