tomoki312
@tomoki312

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

php artisan migrateができない

Q&A

Closed

前提・実現したいこと

laravelとvue.jsでポートフォリオを作成しています。migrationをしたいのですが、エラーが出てしまいます。
以前はできていましたがデプロイを行ってからできなくなってしまいました。

発生している問題・エラーメッセージ

root@c59ef3e3d59a:/work/backend# php artisan migrate

   BadMethodCallException  : Method Illuminate\Database\Schema\Blueprint::string does not exist.

  at /work/backend/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:103
     99|      */
    100|     public function __call($method, $parameters)
    101|     {
    102|         if (! static::hasMacro($method)) {
  > 103|             throw new BadMethodCallException(sprintf(
    104|                 'Method %s::%s does not exist.', static::class, $method
    105|             ));
    106|         }
    107| 

  Exception trace:

  1   Illuminate\Database\Schema\Blueprint::__call("string")
      /work/backend/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:155

  2   Illuminate\Database\Migrations\DatabaseMigrationRepository::Illuminate\Database\Migrations\{closure}(Object(Illuminate\Database\Schema\Blueprint))
      /work/backend/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:166

  Please use the argument -v to see more details.

該当のソースコード

マイグレーションファイル

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Validation\Rules\Unique;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->unique();
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password')->nullable();
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('questions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('title');
            $table->text('body');
            $table->boolean('solution')->default(false);
            $table->bigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('questions');
    }
}

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAnswersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('answers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->text('body');
            $table->bigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->bigInteger('question_id');
            $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('answers');
    }
}

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSympathiesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('likes', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->bigInteger('question_id');
            $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sympathies');
    }
}

試したこと

php artisan migrate:refreshの実行
AppServiceProviderのboolの編集
タイプミスの確認(一つずつ打ち直しました)
php artisan config:cacheの実行

補足情報(FW/ツールのバージョンなど)

laravel 6.20.37
PHP 8.0.13

0

1Answer

Comments

  1. @tomoki312

    Questioner

    ありがとうございました。おかげさまで解決できました。3時間ほどエラー文で調べて解決できなかったので一人では解決できなかったと思います。

Your answer might help someone💌