在 Macroable.php 第 96 行:方法体不存在

Par*_*mba 1 php laravel

我对 Laravel 还很陌生。我创建了一个名为:create_notes_table 的迁移文件,当运行命令 php artisan migrate 时,会弹出此错误消息。

我的 create_notes_table 文件内容

class CreateNotesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('notes', function (Blueprint $table) {
            $table->increments('id');
            $table->number('card_id');
            $table->body('string');
            $table->timestamps();
        });
    }



    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('notes');
    }
}
Run Code Online (Sandbox Code Playgroud)

ker*_*olz 5

正如错误消息所述,迁移中没有body()方法。

https://laravel.com/docs/8.x/migrations#columns

将您的更改function up()为:

public function up()
    {
        Schema::create('notes', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('card_id');
            $table->string('body');
            $table->timestamps();
        });
    }
Run Code Online (Sandbox Code Playgroud)

当我们这样做时,number()也不存在,将其更改为integer() 编辑:更改numberinteger