【发布时间】:2021-12-11 14:30:21
【问题描述】:
刚刚创建了一个新的 laravel 项目并尝试迁移表,我得到了这个:
SQLSTATE[HY000] [2002] 没有这样的文件或目录(SQL: select * from information_schema.tables where table_schema = sugarDaddy and table_name = migrations and table_type = 'BASE TABLE')
我尝试清除缓存、路由、配置,并将 DBHOST 从 127.0.0.1 更改为 localhost 并返回,正如我在几篇文章中看到的那样,但没有任何效果。我将把迁移和 ss 留在这里。
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sugarDaddy
DB_USERNAME=root
DB_PASSWORD=
【问题讨论】:
-
运行
php artisan migrate:fresh的输出是什么?问题中的那个还是其他?另外,我会尝试用sugardaddy或sugar_daddy替换sugarDaddy,以确保大小写不是问题。 -
php artisan migrate:fresh 显示:SQLSTATE[HY000] [2002] Connection denied (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
-
尝试将
DB_HOST更改为localhost再试一次 -
还是一样:SQLSTATE[HY000] [2002] 没有这样的文件或目录(SQL:select * from information_schema.tables where table_schema = sugardaddy and table_name = migrations and table_type = 'BASE TABLE')
-
你确定当你有
DB_HOST=127.0.0.1时你传递了正确的连接数据吗?我的意思是用户名、密码?
标签: php laravel database-migration mamp