0
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 3 years have passed since last update.

間違った名前のマイグレーションファイルを生成してしまった時

Posted at

一つだけロールバックしたい

間違えてCというマイグレーションファイルを作ってしまい
他のは残してCだけロールバックしたい

 Ran? | Migration                                      | Batch |
+------+------------------------------------------------+-------+
| Yes  | xxxx_xx_xx_xxxxxx_create_xxxxx_table           | 1     |
| Yes  | xxxx_xx_xx_xxxxxx_create_xxxxxxx_xxxxxxx_table | 1     |
| Yes  | xxxxx_xx_xx_xxxxxx_create_xxxx_xxxxx_table     | 1     |
| Yes  | xxxxx_xx_xx_xxxxxx_create_xxxxxxx_table        | 1     |
| Yes  | xxxxx_xx_xx_xxxxxx_create_xxxx_table           | 2     |
| Yes  | xxxxx_xx_xx_xxxxx_c                            | 3     |
+------+------------------------------------------------+-----

解決

通常のrollbackコマンドの後ろに--stepオプションをつけると
指定した数字分だけしたからロールバック可能。

php artisan migrate:rollback --step=1

するとちゃんと一つだけロールバックできるわけだ

+-----+------------------------------------------------+-------+
 Ran? | Migration                                      | Batch |
+------+------------------------------------------------+-------+
| Yes  | xxxx_xx_xx_xxxxxx_create_xxxxx_table           | 1     |
| Yes  | xxxx_xx_xx_xxxxxx_create_xxxxxxx_xxxxxxx_table | 1     |
| Yes  | xxxxx_xx_xx_xxxxxx_create_xxxx_xxxxx_table     | 1     |
| Yes  | xxxxx_xx_xx_xxxxxx_create_xxxxxxx_table        | 1     |
| Yes  | xxxxx_xx_xx_xxxxxx_create_xxxx_table           | 2     |
| No   |xxxxx_xx_xx_xxxxxx_c                            | 3     |
+------+------------------------------------------------+-----

あとは普通にファイルを削除してしまってOK。

Railsを使ってた時に何度もお世話になったこのコマンドですが、
急にど忘れしてしまったので備忘録として残します。

0
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
0
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?