dqmq0654 2017-01-01 16:27
浏览 414
已采纳

调用未定义的方法Illuminate \ Database \ Schema \ MySqlBuilder :: dropForeign()

class CreateCommentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email');
            $table->text('comment');

            $table->boolean('approved');
            $table->integer('post_id')->unsigned();
            $table->timestamps();
        });

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

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropForeign(['post_id']);
        Schema::dropIfExists('comments');
    }
}

This is what my migration class looks like, i have been trying to delete the table from the database but it throws me an error.

Error

Call to undefined method Illuminate\Database\Schema\MySqlBuilder::dropForeign()

I have gone through the documentation but it doesnot seem to be of much help.

could anyone please point out my mistake and what would be the solution ?

Just so you know , i am new to laravel.Go easy on me.Thanks!.

  • 写回答

2条回答 默认 最新

  • douye2572 2017-01-01 16:41
    关注

    dropForeign needs to be called under Schema::table with a Blueprint object,

    Schema::table('comments', function (Blueprint $table) {
            $table->dropForeign('comments_post_id_foreign');
        });
    

    This follows the naming convention of <table_name>_<foreign_table_name>_<column_name>_foreign.

    OR

    Schema::table('comments', function (Blueprint $table) {
            $table->dropForeign(['your_key_name']);
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路