简体   繁体   English

错误用户在尝试创建现有表的列时已经退出

[英]Error Users already exits when trying to create a column to an existing table

I'm trying to add a new column to an existing table 'users'. 我正在尝试向现有表“用户”中添加新列。 I created a new migration 'add_privilege_column_to_users_table'. 我创建了一个新的迁移“ add_privilege_column_to_users_table”。 When I try to run the php artisan migration, I get an error that the 'users' table already exists. 当我尝试运行php artisan迁移时,出现一个错误,提示“用户”表已经存在。 Am I missing something here? 我在这里想念什么吗?

I've already tried several methods from Googling and from other people that have had the same problem here at starckoverflow. 我已经尝试了Googling和其他人在starckoverflow遇到相同问题的几种方法。 But none of the code from here helped me. 但是这里的代码都没有帮助我。

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") PDOException::(“ SQLSTATE [42S01]:基本表或视图已存在:1050表'users'已经存在”]

That's the specific error that I get when I run php artisan migrate. 那是我运行php artisan migration时遇到的特定错误。 I'm just trying to add a new column to that table. 我只是想在该表中添加一个新列。

Below is my migration status: 以下是我的迁移状态:

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

It seems you rolled back too far, but your users table was not dropped thus Laravel, when trying to run migrations, is trying to re-create the table. 似乎您回滚的幅度太大,但是您的users表并未删除,因此Laravel在尝试运行迁移时试图重新创建该表。

If you head over to your database, you'll be able to update the migration to say it has already executed thus skipping over that batch. 如果您转到数据库,则可以将迁移更新为已执行迁移,从而跳过该批次。

UPDATE migrations SET batch = 1 WHERE migration = '2014_10_12_000000_create_users_table';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM