php - Laravel 4 - 工作台中的一项迁移可以回滚,而其他迁移则不能

标签 php mysql laravel laravel-4

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

常规迁移示例:

<?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');
}

}

虽然这不能,因为它给出

"Class 'CreatePivotPermissionRole' not found"

错误。

如何解决?

最佳答案

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

关于php - Laravel 4 - 工作台中的一项迁移可以回滚,而其他迁移则不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18470543/

相关文章:

PHP7 + Symfony 3.1.0 + Vagrant : Failed to write session data

php - 如何计算列中相同结果的数量?

php - 更新后台数据库和网站

mysql - 使用相同表排序规则的数据库导出导入中的垃圾数据

php - 我尝试使用 session 数据调用数组上的成员函数 save()

Laravel 电子邮件邮件列表即时本地化

php - 马根托。仅为分组产品创建属性

php - MySQL/PHP mysql_fetch_array() 始终丢失第一行

PHP - 在 txt 文件中缓存 MYSQL 查询是一种好习惯吗?

php - Laravel 5.6 MySQL 服务器已经消失