0

我有两种类型的工作台迁移:创建常规表和为多对多关系创建数据透视表。

定期迁移样本:

<?php

use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
        Schema::create('users', function(\Illuminate\Database\Schema\Blueprint $table)
        {
            $table->increments('id')->unsigned();

            $table->string('login')->unique();
            $table->string('username')->unique();
            $table->string('password');
            $table->string('email');
            $table->boolean('active')->default(true);

            $table->timestamps();
            $table->softDeletes();
        });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
        Schema::dropIfExists('users');
}

}

以上迁移可以回滚

<?php

use Illuminate\Database\Migrations\Migration;

class CreatePivotRoleUser extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
        Schema::create('role_user', function(\Illuminate\Database\Schema\Blueprint $table)
        {   
            $table->integer('role_id')->unsigned();
            $table->integer('user_id')->unsigned();

            $table->primary(['role_id', 'user_id']);

            $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
        Schema::dropIfExists('role_user');
}

}

虽然这不能,因为它给

“找不到类‘CreatePivotPermissionRole’”

错误。

如何解决?

4

1 回答 1

0

您的代码看起来正确。如果没有找到 CreatePivotPermissionRole,则表示它之前已被删除。检查所有 down() 方法的内容,那里一定有问题。

于 2013-08-29T03:34:30.340 回答