Laravel Migration致命错误:调用未定义的方法Illuminate \ Database \ Schema \ Blueprint :: integer()

问题描述 投票:-1回答:3

我的代码:

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration

{
    /**
     * Run the migrations.

     *
     * @return void
     */
    public function up()
    {
        Schema::create('tasks', function (Blueprint $table) {
            $table->increments('id');
             $table->integar('user_id')->index();
            $table->string('name');
            $table->string('food');
            $table->string('quantity');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('tasks');
    }
}
php laravel laravel-5.2
3个回答
14
投票

你错误地写了integer拼写,写这个integer而不是integar

这是我的工作示例代码,请参阅整数行,希望对您有帮助

public function up()
{
    Schema::create('app_type_users', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned()->index();
        $table->integer('app_type_id')->unsigned()->index();
        $table->string('status',1);
        $table->timestamps();
    });
}

1
投票

如果你看到:“调用未定义的方法”错误,通常意味着你拼错了一些东西。我有类似的东西让我发疯,我在链接方法时错过了一个箭头:

Error location

看看这里,它甚至说你需要检查哪一行:Error message注意命令行告诉你的内容,这些提示比我要承认的更明显!


0
投票

转到你的项目文件夹打开app/Providers/AppServiceProvider.php添加以下代码然后在控制台中运行php artisan migrate

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; 

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.