我目前正在通过终端在Laravel中进行迁移,并且在尝试使用php artisan migrate
时遇到这两个错误;我将在下面打印错误:
BadMethodCallException : Method IlluminateDatabaseSchemaBlueprint::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 IlluminateDatabaseSchemaBlueprint::__call("int")
/Users/shaquilenoor/Desktop/chatapi/database/migrations/2019_01_29_045824_create_contacts_table.php:15
2 CreateContactsTable::{closure}(Object(IlluminateDatabaseSchemaBlueprint))
/Users/shaquilenoor/Desktop/chatapi/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:164
似乎这两个错误都源于我的CreateContactsTable,所以我将在下面打印该文件的代码:
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
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');
}
}
错误在行中:
$table->int('room_id')->unique();
没有int
方法。您应该改用integer
:
$table->integer('room_id')->unique();
将$table->int
更改为$table->integer
int
因为该方法不存在