简体   繁体   English

Laravel 2 BadMethodCallException 实例:“int 不存在”和“方法不存在”

[英]Laravel 2 instances of BadMethodCallException: 'int does not exist' and 'method does not exist'

I am currently doing migrations in Laravel via the Terminal, and have these two errors when attempting to use php artisan migrate ;我目前正在通过终端在 Laravel 中进行迁移,并且在尝试使用php artisan migrate时出现这两个错误; I will print errors below:我将在下面打印错误:

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

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

  Exception trace:

  1   Illuminate\Database\Schema\Blueprint::__call("int")
      /Users/shaquilenoor/Desktop/chatapi/database/migrations/2019_01_29_045824_create_contacts_table.php:15

  2   CreateContactsTable::{closure}(Object(Illuminate\Database\Schema\Blueprint))
      /Users/shaquilenoor/Desktop/chatapi/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:164

It seems both errors stem from my CreateContactsTable, so I will print the code from that file below:似乎这两个错误都源于我的 CreateContactsTable,所以我将从下面的文件中打印代码:

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

class CreateContactsTable extends Migration
{
    public function up()
    {
        Schema::create('contacts', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user1_id');
            $table->unsignedInteger('user2_id');
            $table->int('room_id')->unique();
            $table->timestamps();
            $table->foreign('room_id')->references('id')->on('rooms');
            $table->foreign('user1_id')->references('id')->on('users');
            $table->foreign('user2_id')->references('id')->on('users');
        });
    }

    public function down()
    {
        Schema::dropIfExists('contacts');
    }
}

Error is in line:错误是一致的:

$table->int('room_id')->unique();

There is no int method.没有int方法。 You should use integer instead:您应该改用integer

$table->integer('room_id')->unique();

$table->int更改$table->int $table->integer因为int方法不存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM