LoginSignup
7
6

More than 5 years have passed since last update.

モデル生成用マイグレーションファイル作成時のコンフリクトエラーへの対処方法

Last updated at Posted at 2018-06-07

一度消したモデルを再度作成する(モデル名一緒)際に以下のエラーに遭遇。

エラー内容

# bundle exec rails generate model user

      invoke  active_record
    conflict    db/migrate/20180607033653_create_users.rb
Another migration is already named create_destinations: /var/local/lib/app/test_app/db/migrate/20171218094339_create_users.rb. Use --force to replace this migration or --skip to ignore conflicted file.

マイグレーションちゃん真面目。素直に作らせてよ。

対処方法

コンフリクトを回避すためのオプション --skip--force が用意されている。

# マイグレーションファイルの作成だけスキップされる(モデルに関連したファイル群は作成される)
bundle exec rails generate model user -s

# 通常通りマイグレーションファイルが作成される
bundle exec rails generate model user -f

参考記事

7
6
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
7
6