尝试为现有 table 创建列时出现错误用户已存在
Error Users already exits when trying to create a column to an existing table
我正在尝试向现有 table 'users' 添加一个新列。我创建了一个新迁移 'add_privilege_column_to_users_table'。当我尝试 运行 php artisan 迁移时,我收到一条错误消息,指出 'users' table 已经存在。我在这里错过了什么吗?
我已经在 starckoverflow 上尝试了谷歌搜索和其他遇到同样问题的人的几种方法。但是这里的代码 none 帮助了我。
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 迁移时遇到的特定错误。我只是想向 table 添加一个新列。
以下是我的迁移状态:
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
table 并没有被删除,因此 Laravel 在尝试 运行 迁移时正在尝试重新创建 table.
如果您转到数据库,您将能够更新迁移以表明它已经执行,从而跳过该批处理。
UPDATE migrations SET batch = 1 WHERE migration = '2014_10_12_000000_create_users_table';
我正在尝试向现有 table 'users' 添加一个新列。我创建了一个新迁移 'add_privilege_column_to_users_table'。当我尝试 运行 php artisan 迁移时,我收到一条错误消息,指出 'users' table 已经存在。我在这里错过了什么吗?
我已经在 starckoverflow 上尝试了谷歌搜索和其他遇到同样问题的人的几种方法。但是这里的代码 none 帮助了我。
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 迁移时遇到的特定错误。我只是想向 table 添加一个新列。
以下是我的迁移状态:
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
table 并没有被删除,因此 Laravel 在尝试 运行 迁移时正在尝试重新创建 table.
如果您转到数据库,您将能够更新迁移以表明它已经执行,从而跳过该批处理。
UPDATE migrations SET batch = 1 WHERE migration = '2014_10_12_000000_create_users_table';