Search code examples
phplaraveldatabasemigrate

Method Illuminate\Database\Schema\Blueprint::unsignedBidInteger does not exist


PS C:\xampp\htdocs\learning\laragon\lavue> php artisan migrate
Migrating: 2022_07_17_042348_create_transaction_details_table

   BadMethodCallException 

  Method Illuminate\Database\Schema\Blueprint::unsignedBidInteger does not exist.

  at C:\xampp\htdocs\learning\laragon\lavue\vendor\laravel\framework\src\Illuminate\Macroable\Traits\Macroable.php:113
    109▕      */
    110▕     public function __call($method, $parameters)
    111▕     {
    112▕         if (! static::hasMacro($method)) {
  ➜ 113▕             throw new BadMethodCallException(sprintf(
    114▕                 'Method %s::%s does not exist.', static::class, $method
    115▕             ));
    116▕         }
    117▕

  1   

error in terminal

C:\xampp\htdocs\learning\laragon\lavue\database\migrations\2022_07_17_042348_create_transaction_details_table.php:18 Illuminate\Database\Schema\Blueprint::__call()

  2   C:\xampp\htdocs\learning\laragon\lavue\vendor\laravel\framework\src\Illuminate\Database\Schema\Builder.php:256
      Illuminate\Database\Migrations\Migration@anonymous\C:\xampp\htdocs\learning\laragon\lavue\database\migrations\2022_07_17_042348_create_transaction_details_table.php:7$b5::{closure}()

this my php migration

    <?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('transaction_details', function (Blueprint $table) {
            $table->id();
            $table->unsignedBidInteger('transaction_id');
            $table->unsignedBigInteger('book_id');
            $table->integer('qty');
            $table->timestamps();

            $table->foreign('transaction_id')->references('id')->on('transactions');
            $table->foreign('book_id')->references('id')->on('books');

        });
    }

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

};

When i put php artisan migration sees an error like above


Solution

  • There is a typo in your migration file on 'transaction_id' declaration.

    Your migration file should be like this. Check the line with the comment.

    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    return new class extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('transaction_details', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('transaction_id'); // instead of $table->unsignedBidInteger('transaction_id')
                $table->unsignedBigInteger('book_id');
                $table->integer('qty');
                $table->timestamps();
    
                $table->foreign('transaction_id')->references('id')->on('transactions');
                $table->foreign('book_id')->references('id')->on('books');
    
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
    public function down()
    {
        Schema::dropIfExists('transaction_details');
    }
    

    Kindly read this.