php - Laravel 5 migration identifier name too long -


i trying run following migration:

public function up() {     schema::create('lifestyle_questions', function(blueprint $table)     {         $table->increments('id');         $table->string('question');         $table->timestamps();     });      schema::create('lifestyle_question_answers', function(blueprint $table)     {         $table->increments('id');         $table->integer('lifestyle_question_id')->unsigned();         $table->foreign('lifestyle_question_id')->references('id')->on('lifestyle_questions');         $table->string('answer');         $table->timestamps();     });      schema::create('user_lifestyle_question_answers', function(blueprint $table)     {         $table->integer('user_id')->unsigned();         $table->foreign('user_id')->references('id')->on('users');         $table->integer('lifestyle_question_answer_id')->unsigned();         $table->foreign('lifestyle_question_answer_id')->references('id')->on('lifestyle_question_answers');     }); } 

but following error:

[illuminate\database\queryexception] sqlstate[42000]: syntax error or access violation: 1059 identifier name 'user_lifestyle_question_answers_lifestyle_question_answer_id_foreign' long (sql: alter table `user_lifestyle_question_answers` add constraint user_lifestyle_question_answers_lifestyle_question_answer_id_foreign foreign key (`lifestyle_question_answer_id`) references `lifestyle_question_answers` (`id`))  [pdoexception] sqlstate[42000]: syntax error or access violation: 1059 identifier name 'user_lifestyle_question_answers_lifestyle_question_answer_id_foreign' long 

searching on google found this

"you can pass custom index name second parameter foreign() method. or use shorter table/column names."

so want like

public function up() {     schema::create('lifestyle_questions', function(blueprint $table)     {         $table->increments('id');         $table->string('question');         $table->timestamps();     });      schema::create('lifestyle_question_answers', function(blueprint $table)     {         $table->increments('id');         $table->integer('lifestyle_question_id')->unsigned();         $table->foreign('lifestyle_question_id', 'lq_id_foreign')->references('id')->on('lifestyle_questions');         $table->string('answer');         $table->timestamps();     });      schema::create('user_lifestyle_question_answers', function(blueprint $table)     {         $table->integer('user_id')->unsigned();         $table->foreign('user_id')->references('id')->on('users');         $table->integer('lifestyle_question_answer_id')->unsigned();         $table->foreign('lifestyle_question_answer_id', 'lqa_id_foreign')->references('id')->on('lifestyle_question_answers');     }); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -