2015-10-05 10 views
15

मेरा मेरा 2015_09_14_051851_create_orders_table.php है। और मैं $ table-> पूर्णांक ('category_id') बदलना चाहता हूं; नए माइग्रेशन के साथ एक स्ट्रिंग के रूप में।लार्वेल माइग्रेशन टेबल फ़ील्ड का प्रकार

<?php 

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateOrdersTable extends Migration { 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('orders', function(Blueprint $table) 
     { 
      $table->increments('id'); 
      $table->string('num'); 
      $table->integer('user_id'); 

      $table->text('store_name'); 
      $table->integer('store_name_publication'); 

      $table->string('postal_code', 255); 
      $table->string('phone_number', 255); 

      $table->text('title'); 
      $table->text('description'); 

      $table->string('list_image_filename1', 255); 
      $table->string('list_image_filename2', 255)->nullable(); 
      $table->string('list_image_filename3', 255)->nullable(); 
      $table->string('list_image_filename4', 255)->nullable(); 
      $table->string('list_image_filename5', 255)->nullable(); 

      $table->integer('term'); 

      $table->datetime('state0_at')->nullable(); 
      $table->datetime('state1_at')->nullable(); 
      $table->datetime('state2_at')->nullable(); 
      $table->datetime('state3_at')->nullable(); 
      $table->datetime('state4_at')->nullable(); 
      $table->datetime('state5_at')->nullable(); 
      $table->datetime('state6_at')->nullable(); 
      $table->datetime('state7_at')->nullable(); 
      $table->datetime('state8_at')->nullable(); 
      $table->datetime('state9_at')->nullable(); 
      $table->datetime('state10_at')->nullable(); 

      $table->integer('category_id'); 
      $table->integer('target_customer_sex'); 
      $table->integer('target_customer_age'); 

      $table->integer('payment_order'); 
      $table->integer('num_comment'); 
      $table->integer('num_view'); 
      $table->string('num_pop'); 

      $table->integer('money'); 
      $table->integer('point'); 

      $table->datetime('closed_at'); 
      $table->timestamps(); 
      $table->softDeletes(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('orders'); 
    } 

} 
+0

'$ टेबल> स्ट्रिंग ('category_id');' कोई मैं अन्य माइग्रेशन फ़ाइल का उपयोग ही नहीं प्रकार परिवर्तित करना चाहते – aldrin27

+0

2015_10_05_021049 _change_category_id_to_orders_table –

उत्तर

19

मौजूदा डाटाबेस के लिए कुछ परिवर्तन करने के लिए, तो आप माइग्रेशन में change() का उपयोग करके स्तंभ प्रकार बदल सकते हैं।

यह आपको क्या कर सकते हैं

Schema::table('orders', function ($table) { 
    $table->string('category_id')->change(); 
}); 

कृपया ध्यान दें कि आप आप इसे यहाँ पा सकते हैं http://laravel.com/docs/5.1/migrations#modifying-columns

+1

अब मैं लार्वेल 4.2 –

14

standard solution didn अधिक जानकारी के लिए composer.json को सिद्धांत/dbal निर्भरता जोड़ने की जरूरत है टेक्स्ट से LONGTEXT से प्रकार बदलते समय मेरे लिए काम नहीं करते हैं।

मैं इस तरह यह करना पड़ा:

public function up() 
{ 
    DB::statement('ALTER TABLE mytable MODIFY mycolumn LONGTEXT;'); 
} 

public function down() 
{ 
    DB::statement('ALTER TABLE mytable MODIFY mycolumn TEXT;'); 
} 

यह एक सिद्धांत समस्या हो सकती है। अधिक जानकारी here

Schema::table('mytable', function ($table) { 
     // Will set the type to LONGTEXT. 
     $table->string('mycolumn', 4294967295)->change(); 
    }); 
+2

का उपयोग कर रहा हूं यह डेसिमल कॉलम के लिए विशेष रूप से उपयोगी है। – dmmd

+1

धन्यवाद आदमी, आपने मेरा दिन बचा लिया है) –

+1

मैं इस व्यवहार की पुष्टि कर सकता हूं। टेक्स्ट से मध्यम टेक्स्ट में कॉलम बदलने के लिए मुझे यह करना था: $ table-> स्ट्रिंग ('संदेश', 16777215) -> शून्य() -> बदलें(); – Antonio

0

मेरे लिए समाधान सिर्फ सूचकांक

साथ अहस्ताक्षरित की जगह किया गया था:

यह करने के लिए एक और तरीका है स्ट्रिंग() विधि का उपयोग करने, और पाठ प्रकार अधिकतम लंबाई करने के लिए मान सेट है पूर्ण कोड

Schema::create('champions_overview',function (Blueprint $table){ 
     $table->engine = 'InnoDB'; 
     $table->increments('id'); 
     $table->integer('cid')->index(); 
     $table->longText('name'); 
    }); 


    Schema::create('champions_stats',function (Blueprint $table){ 
     $table->engine = 'InnoDB'; 
     $table->increments('id'); 
     $table->integer('championd_id')->index(); 
     $table->foreign('championd_id', 'ch_id')->references('cid')->on('champions_overview'); 
    }); 
संबंधित मुद्दे