2015-05-11 15 views
11

मैं निम्न माइग्रेशन चलाने के लिए कोशिश कर रहा हूँ:Laravel 5 प्रवास पहचानकर्ता का नाम बहुत लंबा

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'); 
    }); 
} 

लेकिन मैं निम्नलिखित त्रुटि मिलती है:

[Illuminate\Database\QueryException] 
SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'user_lifestyle_question_answers_lifestyle_question_answer_id_foreign' is too 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' is too long 

उत्तर

37

आप दूसरे रूप में एक कस्टम सूचकांक नाम पारित कर सकते हैं विदेशी() विधि में पैरामीटर। या बस छोटी तालिका/कॉलम नामों का उपयोग करें।

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

यही चाल धन्यवाद किया:

तो आप की तरह कुछ करना चाहता हूँ! – geoffs3310

+1

बस जानकारी के लिए: http://dev.mysql.com/doc/refman/5.5/en/identifiers.html के अनुसार MySQL पहचानकर्ताओं को हमेशा 64 वर्णों से कम होना चाहिए –

संबंधित मुद्दे