php - How can i rename column in laravel using migration? -
i have column in below:
public function up() { schema::create('stnk', function(blueprint $table) { $table->increments('id'); $table->string('no_reg', 50)->unique(); $table->string('no_bpkb', 50)->unique(); $table->string('nama_pemilik', 100); $table->string('alamat'); $table->string('merk', 50); $table->string('tipe', 50); $table->string('jenis', 50); $table->smallinteger('tahun_pembuatan'); $table->smallinteger('tahun_registrasi'); $table->smallinteger('isi_silinder'); $table->string('no_rangka', 50); $table->string('no_mesin', 50); $table->string('warna', 50); $table->string('bahan_bakar', 50); $table->string('warna_tnkb', 50); $table->string('kode_lokasi', 50); $table->date('berlaku_sampai'); $table->timestamps(); $table->index('created_at'); $table->index('updated_at'); }); }
i have create seeder stnk table
and want rename id
id_stnk
. i've added "doctrine / dbal" in "composer" , composer update
.
i've create migration php artisan migration:make rename_column
, added new methode rename_column:
schema::table('stnk', function(blueprint $table) { $table->renamecolumn('id', 'id_stnk'); });
and i've seek run command php artisan migrate
and have error this:
[ulluminate\database\queryexception] sqlstate[hy000]: general error: 1025 error on rename of './my_database/#sql -447_33' './my_database/stnk' (error: 150) (sql: alter table stnk alter id id_stnk int unsigened auto_increment not null) [pdoexception] sqlstate[hy000]: general error: 1025 error on rename of './my_database/#sql -447_33' './my_database/stnk' (error: 150)
you need create migration file - , place in there:
run
laravel 4: php artisan migrate:make rename_stnk_column laravel 5: php artisan make:migration rename_stnk_column
then within new migration file place:
class renamestnkcolumn extends migration { public function up() { schema::table('stnk', function($t) { $t->renamecolumn('id', 'id_stnk'); }); } public function down() { schema::table('stnk', function($t) { $t->renamecolumn('id_stnk', 'id'); }); } }
php mysql database laravel migration
No comments:
Post a Comment