我正在关注 Laracasts TDD,但遇到了一个错误,无论我做什么都无法解决。当我尝试迁移时,它向我显示此错误:
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table birdboard。#sql-14b8_86(errno: 150 "Foreign key constraint is wrongly forms") (SQL: alter table projectsadd constraint projects_owner_id_foreignforeign key ( owner_id) 引用users( id))
我知道 Laravel 现在使用 unsignedBigInteger 而不是 unsignedInteger 和 bigIncrements 而不是 Increments。我已经完成了所有这些。在我的 AppServiceProvider.php 中,我还添加了:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
应用服务提供商:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
Schema::defaultStringLength(191);
}
}
创建项目表
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProjectsTable extends Migration
{
public function up()
{
Schema::create('projects', function (Blueprint $table) {
Schema::dropIfExists('projects');
$table->bigIncrements('id');
$table->unsignedBigInteger('owner_id');
$table->string('title');
$table->text('description');
$table->timestamps();
$table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
});
}
public function down()
{
Schema::dropIfExists('projects');
}
}
你能告诉我我的代码有什么问题吗?为什么会出现错误? https://prnt.sc/p5ku4x
MYYA