当我想要运行 php artisan migrate 时,出现了这个错误。错误消息如下:
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_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:\composer\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671 667▕ // If an exception occurs when attempting to run a query, we'll format the error 668▕ // message to include the bindings with SQL, which will make this exception a 669▕ // lot more helpful to the developer instead of just the database's errors. 670▕ catch (Exception $e) { ➜ 671▕ throw new QueryException( 672▕ $query, $this->prepareBindings($bindings), $e 673▕ ); 674▕ } 675▕
1
C:\composer\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464 PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists")2
C:\composer\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:464 PDOStatement::execute()
数据库设置如下。 Database.php 文件中的设置如下:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
.env 文件中的设置如下。APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:sBKduFaKhOJdg7/A1U4IzAUnj3yLLcjngjmMvEoWl94=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
注意:我在wampserver中使用mysql。
1050表'users'已经存在
,你能看到它所说的错误是users
已经存在,所以不能再创建了,或者你可以尝试php artisan migrate:fresh
。 - Kamlesh Paul