我是Laravel和php的新手,所以我面对和错误,我不知道如何解决。
基本的问题是,因为很多表都有primary:id
和created_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] Declaration of CreateItemsTable::up() should be compatible with 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();
});
}
// ......
}