2013-09-25 16 views
8

यहाँ मेरी माइग्रेशन कोड है:Laravel 4 प्रवासन - विदेशी कुंजी बाधा नहीं जोड़ा जा सकता

public function up() 
{ 
    Schema::create('foos', function(Blueprint $table) { 
     // Primary key 
     $table->increments('id'); 

     // Standard 
     $table->engine = 'InnoDB'; 
     $table->timestamps(); 
     $table->softDeletes(); 
    }); 

    Schema::create('bars', function(Blueprint $table) { 
     // Primary key 
     $table->increments('id'); 

     // Define foreign key 
     $table->integer('foo_id')->unsigned; 

     // Foreign key contraints 
     // NOTE: causes "General error: 1215 Cannot add foreign key constraint" 
     // $table->foreign('foo_id')->references('id')->on('foos'); 

     // Standard 
     $table->engine = 'InnoDB'; 
     $table->timestamps(); 
     $table->softDeletes(); 
    }); 
} 

public function down() 
{ 
    Schema::drop('foos'); 
    Schema::drop('bars'); 
} 

विदेशी कुंजी बाधा परिभाषित करने के लिए कोड बाहर टिप्पणी नहीं की जाती है, तो मैं कमांड लाइन पर निम्नलिखित त्रुटि मिलती है: जनरल त्रुटि: 1215 विदेशी कुंजी बाधा नहीं जोड़ सकता है।

कोई विचार क्या मैं गलत कर रहा हूं?

उत्तर

16
$table->integer('foo_id')->unsigned; 

$table->integer('foo_id')->unsigned(); 

होना चाहिए या आप लघु संस्करण का उपयोग कर सकते: "रवींद्र"

$table->unsignedInteger('foo_id'); 
+1

होमर के प्रसिद्ध शब्दों में। धन्यवाद! – StackOverflowNewbie

+5

अपने आप को मत मारो - मैं केवल आपके प्रश्न का उत्तर दे सकता हूं क्योंकि मैंने वही काम किया था। :-) – ceejayoz

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