【发布时间】:2022-01-23 11:21:16
【问题描述】:
我是 laravel 新手,我是初学者,我在 laravel 表中运行 php artisan migrate 时遇到问题。
C:\wamp64\www\my-blog>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(255) not null, `email` varchar(255) not null, `email_verified_at` timestamp null, `password` varchar(255) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
at C:\wamp64\www\my-blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:703
699▕ // If an exception occurs when attempting to run a query, we'll format the error
700▕ // message to include the bindings with SQL, which will make this exception a
701▕ // lot more helpful to the developer instead of just the database's errors.
702▕ catch (Exception $e) {
➜ 703▕ throw new QueryException(
704▕ $query, $this->prepareBindings($bindings), $e
705▕ );
706▕ }
707▕ }
1 C:\wamp64\www\my-blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:492
PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")
2 C:\wamp64\www\my-blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:492
PDOStatement::execute()
【问题讨论】:
-
错误很明显。您正在尝试创建一个已存在于数据库中的表。
-
如果您之前运行过迁移,则需要运行
php artisan migrate:fresh或php artisan migrate:refresh或运行php artisan migrate:rollback,然后运行php artisan migrate
标签: laravel database error-handling