由于我没有创建用户表,无法进行迁移。

15 浏览
0 Comments

由于我没有创建用户表,无法进行迁移。

我正试图为我的方案创建一个新表的迁移,但当我运行php artisan migrate时,我遇到了以下错误:

Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(191) not null, `email` varchar(191) not null, `email_verified_at` timestamp null, `password` varchar(191) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

这个迁移不是我创建的,它是通过php artisan make:auth自动生成的,据我所知,它已经运行过了,因为用户表已经存在并且正在运行,所以我不知道该怎么解决它。非常感谢您的帮助。

0
0 Comments

问题出现的原因是因为在进行迁移时,发现了一个名为"users"的表,但是这个表并不是我创建的。

解决方法是首先尝试运行"php artisan migrate:reset"命令来重置迁移并删除"users"表。如果这个命令没有起作用并且出现错误,请登录到phpmyadmin页面并手动删除这个表。

在再次运行"php artisan migrate"命令之前,确保在"create_users_table"迁移文件的底部有以下代码段:

void
public function down()
{
    Schema::dropIfExists('users');
}

这样,当运行"php artisan migrate:refresh"命令时,它将删除当前的"users"表并重新创建它。

0