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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36788572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:39:19  来源:igfitidea点击:

Laravel Migration Fatal error: Call to undefined method Illuminate\Database\Schema\Blueprint::integar()

phplaravellaravel-5.2

提问by Haseeb Haider Zaidi

My code:

我的代码:

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');
    }
}

回答by Qazi

You wrongly written integerspelling, write this integerinstead integar

你写错integer拼音,写这篇文章integer,而不是integar

Here is my working sample code, see the integer line, I hope that might help you

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

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();
    });
}

回答by Mirza Sisic

If you see a: "Call to undefined method" error it usually means you have misspelled something. I had something similar drive me crazy and I had just missed an arrow when chaining methods:

如果您看到:“调用未定义方法”错误,通常意味着您拼错了某些内容。我有类似的事情让我发疯,并且在链接方法时我刚刚错过了一个箭头:

Error location

错误位置

Just take a look here, it even says which line you need to check: Error messagePay attention to what the command line is telling you, those hints are more obvious than I'd care to admit!

看看这里,它甚至说你需要检查哪一行: 错误信息注意命令行告诉你的,这些提示比我愿意承认的更明显!

回答by Anisul Islam

Go to your project folder open app/Providers/AppServiceProvider.phpadd the following code then run php artisan migratein console.

转到您的项目文件夹,打开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()
    {
        //
    }
}