【问题标题】:Migration:Reference method is not found in subject class迁移:在主题类中找不到参考方法
【发布时间】:2018-04-04 13:26:00
【问题描述】:
>  Schema::create('password_resets', function (Blueprint $table) {
>  $table->string('email')**->index();**
>  $table->string('token');
>  $table->timestamp('created_at')**->nullable();**

在迁移文件phpstorm中说的是

找不到方法“索引” Illuminate\Support\Fluent在主题类中找不到引用的方法。

在任何迁移失败中,我都不能像这样链接:

 Schema::table('posts', function (Blueprint $table) {           
       $table->unsignedInteger('user_id');        
       $table->foreign('user_id')->references('id')->on('users');
 }

【问题讨论】:

    标签: php laravel-5 migration


    【解决方案1】:

    这是预期行为,因为 index()Blueprint 中定义 - 而不是在 Fluent 中定义。

    将您的代码更改为以下内容:

    // Create column
    $table->string('email');
    
    // Create the index
    $table->index('email');
    
    // Or, to create multiple indexes:
    $table->index(['email', 'other_column']);
    

    您可以阅读有关创建索引的更多信息here

    【讨论】:

    • $table->foreign('user_id')->references('id')->on('users');当我使用references() 时找不到相同的引用..
    • @savamilin 你在哪里得到这个错误?我怀疑这只是你的 IDE 抱怨。尝试运行迁移,因为这应该可以工作。
    • @savamilin 以后请为您的问题创建单独的问题。
    • 好的,谢谢你的建议,我会分开问题。在 IDE PHPSTORM 中是的。当我运行迁移时,他工作。但我不知道方法是否有效,因为方法上有黄色错误,它向我显示在 Illuminate\Support\Fluent 中找不到方法“索引”,引用的方法是在主题类中找不到。或第二个问题的参考资料。
    猜你喜欢
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 1970-01-01
    相关资源
    最近更新 更多