2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FuelPHPのマイグレーションファイルによるマイグレーションで列名を変更する方法

2
Posted at

コマンドラインから列名を変更するマイグレーションの情報は探せばすぐに見つかるのですが、
マイグレーションファイルによるマイグレーションで列名を変更するやり方がすぐに見つかりませんでした…

この場合以下のように記載すればOKです。

<?php

namespace Fuel\Migrations;

/**
 * foo_tableのbarの列名をhogeに変更する
 */
class Modify_rename_bar_foo_table
{
	public function up()
	{
		\DBUtil::modify_fields('foo_table', array(
			'bar' => array('constraint' => 11, 'type' => 'int', 'name' => 'hoge'),
		));
	}

	public function down()
	{
		\DBUtil::modify_fields('foo_table', array(
			'hoge' => array('constraint' => 11, 'type' => 'int', 'name' => 'bar'),
		));
	}
}

注意する点として
'bar' => array('name' => 'hoge'), と列名だけ記載した場合はエラーになります。
横着して変更したいものだけ書くとエラーになります。
列名だけ変更する場合でも全ての情報を含めてあげましょう。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?