【发布时间】:2021-12-30 10:19:24
【问题描述】:
BadMethodCallException ... 方法 Illuminate\Database\Schema\Blueprint::after 不存在。 我无法为我的项目迁移我的数据库...这是我面临的错误
.................................................. .........................
cmd 错误,(我迁移失败):
E:\xampp\htdocs\face_clone1>php artisan migrate
Migrating: 2021_11_19_104856_update_users_table
BadMethodCallException
Method Illuminate\Database\Schema\Blueprint::after does not exist.
at E:\xampp\htdocs\face_clone1\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|
• Bad Method Call: Did you mean Illuminate\Database\Schema\Blueprint::date() ?
1 E:\xampp\htdocs\face_clone1\database\migrations\2021_11_19_104856_update_users_table.php:23
Illuminate\Database\Schema\Blueprint::__call("after")
2 E:\xampp\htdocs\face_clone1\vendor\laravel\framework\src\Illuminate\Database\Schema\Blueprint.php:88
UpdateUsersTable::{closure}(Object(Illuminate\Database\Schema\Blueprint))
E:\xampp\htdocs\face_clone1>
我的代码在这里:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table){
$table->after('name', function ($table){
$table->renameColumn('name', 'fname');
$table->string('lname');
$table->boolean('sex');
$table->date('b_day')->default('2021-01-01');
$table->string('image');
});
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
【问题讨论】:
-
你使用的是什么版本的 Laravel?
-
after是 added in 8.27,因此请确保您至少使用该版本。 -
laravel 版本 ^7.29
-
你也可以使用 AFTER 作为 raw