Laravel 5 migration identifier name too long

前端 未结 1 1345
梦如初夏
梦如初夏 2021-02-02 05:39

I am trying to run the following migration:

public function up()
{
    Schema::create(\'lifestyle_questions\', function(Blueprint $table)
    {
        $table-&g         


        
相关标签:
1条回答
  • 2021-02-02 06:14

    You can pass a custom index name as the second parameter into the foreign() method. Or just use shorter table/column names.

    So you want to do something 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');
        });
    }
    
    0 讨论(0)
提交回复
热议问题