迁移会在 Laravel 5.3 的数据透视迁移后生成异常。
schema1 : software_houses
schema2 : skill_domains
我生成了命令make:migration:pivot skill_domains software_houses
并且迁移是通过 skill_domain_software_house
的名称创建的但是当我执行php artisan migrate
时发生以下错误:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'CreateSkillDomainSoftwareHousePivotTable' not found
SKILL Domain
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSkillDomainsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('skill_domains', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('skill_domains');
}
}
软件公司
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSoftwareHousesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('software_houses', function (Blueprint $table) {
$table->increments('id');
$table->string('name',100)->unique();
$table->string('desc',500);
$table->string('url',100);
$table->string('rating')->default('3');
$table->string('logo')->nullable();
$table->string('city')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('software_houses');
}
}
运行make:migration :: pivot命令后创建的数据透视表
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSkill_domainSoftware_housePivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('skill_domain_software_house', function (Blueprint $table) {
$table->integer('skill_domain_id')->unsigned()->index();
$table->foreign('skill_domain_id')->references('id')->on('skill_domains')->onDelete('cascade');
$table->integer('software_house_id')->unsigned()->index();
$table->foreign('software_house_id')->references('id')->on('software_houses')->onDelete('cascade');
$table->primary(['skill_domain_id', 'software_house_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('skill_domain_software_house');
}
}
答案 0 :(得分:0)
尝试使用以下类名称行:
class SkillDomainsSoftwareHouses extends Migration
确保文件名应与班级名称Documentation匹配。
<强>更新强>
我想你应该试试这个:
首先删除上面的software_houses,从迁移文件夹中的skill_domains也从数据库中的迁移表中删除,然后按照以下步骤操作:
1) php artisan make:migration skilldomain
2) php artisan make:migration softwarehouses
3) php artisan make:migration:pivot skilldomains softwarehouses
4) php artisan migrate