LoginSignup
1
0

More than 3 years have passed since last update.

マイグレーションファイルの記述を間違えてしまった

Posted at

本日の学習のハマってしまったエラー内容の備忘録です。

マイグレーションファイルの記述を間違えてしまった時の対処法

本日の学習中に
bundle exec rake db:seedを実行したいのにエラーが出てしまい
原因を探していたらマイグレーションファイルの記述ミスでした。
書き直して上書き保存してもエラーになっていましたので
ターミナルから変更するのだろうかと考え、調べていました。

今日作っていたのは下記のコード

class CreateItems < ActiveRecord::Migration[5.2]
  def change
    create_table :items do |t|
      t.string :items <= nameに変更
      t.integer :price
      t.integer :user_id
      t.timestamps
    end
  end
end

上記のコードのitemsnameに変更した後に

bundle exec rake db:migrate:reset

マイグレーションファイルをリセットして再度マイグレーションを実行します。
※自分は実行しましたが、必要ないかも?

bundle exec rake db:migrate

このやり方で一応は成功しました。

調べていたら
rake db:rollback
などもあるとの事なので今度テスト環境で試してみたいです。

参考:http://railsdoc.com/references/rake%20db:migrate

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