php - Laravel 迁移继承不起作用

标签 php database laravel migration php-7

我是 Laravel 和 php 的新手,所以我遇到了错误,我不知道如何解决。

基本问题是,由于很多表都有 primary:idcreated_by,updated_by 列,我发现在迁移中继承了它们。

我使用的是 php7

所以我有一个基类

class BaseMigration extends Migration {

  public function up(string $tableName) {
    Schema::create($tableName, function (Blueprint $table) {
      $table->mediumIncrements('id');
      $table->primary('id');

      $table->unsignedMediumInteger('created_by')->references('id')->on('users');
      $table->unsignedMediumInteger('updated_by')->references('id')->on('users');
    });
  }
}

以及扩展迁移

class CreateItemsTable extends BaseMigration {

    public function up() {
        parent::up('items');

        Schema::create('items', function (Blueprint $table) {

          $table->string('name', 74);
          $table->timestamps();
        });
    }

    // ......
}

但是 php artisan migrate 给了我这个:

[ErrorException] CreateItemsTable::up() 声明应与 Illuminate\Database\Migrations\BaseMigration::up(string $tableName) 兼容

是因为我运行了两次 up() 吗?

我错过了什么?感谢您的帮助。

最佳答案

我认为您需要具有相同的函数签名,因此传递string $tableName:

class CreateItemsTable extends BaseMigration {

    public function up(string $tableName) {
        Schema::create('items', function (Blueprint $table) {
          parent::up('items');

          $table->string('name', 74);
          $table->timestamps();
        });
    }

    // ......
}

关于php - Laravel 迁移继承不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40069868/

相关文章:

sql-server - 如何减少 MS SQL 数据库的日志文件大小

java - 从我的应用程序运行例行备份

php - 在 Laravel 上手动登录到与默认连接不同的连接

php - Laravel Route 无法工作错误是尝试获取非对象的属性

php mysql 在转换日期格式时的情况

php - WordPress的慢查询杀死服务器。如何找到原产地?

c++ - 获取、修改二进制文件的信息?

mysql - 拉拉维尔 5 : inserting only if all values exist

php - Composer autoload-dev 不工作

php - 即使没有哈希也不读取数据库