0

マスターテーブル POll

 public function up()
    {
        Schema::create('poll', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string('poll_question', 255);
            $table->boolean('status',1)->default(0)->index();
            $table->unsignedInteger('order');
        });
    }

詳細表

  public function up()
    {
        Schema::create('poll_option', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->integer('poll_id');
            $table->string('poll_option', 255);
            $table->unsignedInteger('vote_poll_option');
            $table->unsignedInteger('order');
            $table->boolean('status',1)->default(0)->index();

            $table->foreign('poll_id')->references('id')->on('poll')->onUpdate('cascade')->onDelete('cascade');
        });
    }

外部キーでphp artisanを実行すると

SQLSTATE[HY000]: 一般エラー: 1005 テーブルを作成できませんmydb#sql-6f4_433(エラー番号: 150 "外部キー制約の形式が正しくありません")

注:私はすでにlaravel 5.2とmysqlタイプを使用していますInnodbが正しく形成されない主な原因は何ですか

4

1 に答える 1

0

詳細表で

public function up()
    {
        Schema::create('poll_option', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->integer('poll_id')->unsigned(); //Change Here
            $table->string('poll_option', 255);
            $table->unsignedInteger('vote_poll_option');
            $table->unsignedInteger('order');
            $table->boolean('status',1)->default(0)->index();

            $table->foreign('poll_id')
              ->references('id')->on('poll')
              ->onDelete('CASCADE')
              ->onUpdate('CASCADE');
        });
    }

これはあなたのために働くでしょう

于 2016-07-21T14:36:53.950 に答える