【问题标题】:Laravel 4 - one migrations in workbench can be rolled back, while others cannotLaravel 4 - 工作台中的一个迁移可以回滚,而其他迁移则不能
【发布时间】:2013-08-30 12:02:57
【问题描述】:

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

常规迁移示例:

<?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’”

错误。

如何解决?

【问题讨论】:

  • 我也没有看到 CreatePivotPermissionRole 定义。您是否尝试过运行 composer dump-auto 来推动类加载器?
  • @Iserni 我给了随机样本,CreatePivotRoleUser 也有同样的错误。是的,我尝试轻推自动加载器。并且迁移工作,只有回滚失败。

标签: php mysql laravel laravel-4


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-06-21
    • 2013-06-14
    • 2021-07-01
    • 2018-09-06
    • 2018-08-01
    • 2015-06-23
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多