首页 > 解决方案 > 由于我没有制作用户表,无法进行迁移

问题描述

我正在尝试为我的方案迁移一个新表,当我运行 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 自动提供的,据我所知,它已经运行,因为 users 表已启动并正在运行,所以我不知道如何解决它。任何帮助将不胜感激

标签: laraveldatabase-migration

解决方案


尝试运行 php artisan migrate:reset 如果它不起作用并且给你一个错误登录到你的 phpmyadmin 页面并手动删除它。

但在再次运行 php artisan migrate 之前,请确保此代码位于 create_users_table 迁移文件的底部:

 @return void

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

所以当你运行 php artisan migrate:refresh 时,它会删除当前表并重新创建它


推荐阅读