【发布时间】:2020-09-26 06:09:31
【问题描述】:
我正在使用 laravel 构建管理应用程序。我正在尝试在 laravel 中创建表“role_user”,但是当我运行“php artisan migrate”命令时,我得到以下信息:BadMethodCallException 方法 Illuminate\Database\Schema\Blueprint::name 不存在。谁能告诉你这个错误是什么意思?
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->name();
$table->timestamps();
});
}
但如果我想迁移,我会看到
λ php artisan migrate
Migrating: 2020_06_07_055653_create_roles_table
BadMethodCallException
Method Illuminate\Database\Schema\Blueprint::name does not exist.
at E:\laragon\www\os\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::rename() ?
1 E:\laragon\www\os\database\migrations\2020_06_07_055653_create_roles_table.php:18
Illuminate\Database\Schema\Blueprint::__call("name", [])
2 E:\laragon\www\os\vendor\laravel\framework\src\Illuminate\Database\Schema\Builder.php:166
CreateRolesTable::{closure}(Object(Illuminate\Database\Schema\Blueprint))
【问题讨论】:
-
我是漂亮的用户,你不需要 $table->id();打电话
-
好的,我删除了 $table->id();但还是有这个问题
-
这不是正确的迁移文件,文件的类是
CreateRoleUserTable,所以你的迁移文件命名为create_role_user_table,而你的错误来自create_roles_table -
谢谢,修复它。
-
$table->name();不存在,可能是$table->string('name');laravel.com/docs/7.x/migrations#creating-columns