【发布时间】:2019-02-09 08:07:20
【问题描述】:
我已经在我的 Macbook Pro(运行 High Sierra (10.13.6))上使用 Homebrew 安装了 Laravel 5 和 Valet (v2.0.12)。我已经下载了一个干净的 Laravel 项目 (laravel new blog)。
当我尝试迁移(坐在项目文件夹中,然后使用php artisan migrate)时,什么也没有发生。终端只是坐在那里无所事事。命令正在执行,但什么也没有。没有错误,没有成功,什么都没有。即使添加 -v 也没有任何效果。
我可以通过命令行进入服务器。我在.env 文件中输入了正确的凭据。我什至可以运行其他php artisan 命令,但所有migrate 命令都不执行任何操作。
我的迁移文件是:
2018_09_04_100609_create_users_table.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
2018_09_04_100659_create_password-resets_table.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}
更新:
使用以下方法检查数据库连接:
try {
DB::connection();
die("success!");
} catch (\Exception $e) {
die("Could not connect to the database. Please check your configuration. error:" . $e );
}
我得到了“成功!”。
但后来我将DB::connection() 更改为DB::connection()->getPdo() 它不再执行任何操作。还是不相关?
【问题讨论】:
-
愿意分享您的迁移文件吗?没有它,我们只能猜测。
-
你在迁移文件夹中建表了吗?
-
我已将代码添加到我的原始帖子中。
-
试试 php artisan migrate --force
-
@Mtxz stackoverflow.com/questions/33432752/…检查这个问题,你也可以分享你的env文件(db部分)
标签: php laravel laravel-artisan artisan-migrate