0
0

rails db:migrate マイグレーションの種類とエラー

Last updated at Posted at 2024-02-28

rails db:migrate

データーベースを作るの意味


rails db:rollback

データーべースに作ったカラム(名前)などの追加や編集をしたい場合にロールバックをして1度戻す
その後再度rails db:migrate をする

そして今回のエラーですが
db>migrate内にあるactiverecord内で


  def change
    create_table :addresses do |t|
      t.string :zip_code,                                    null: false
      t.references :region_of_shipping_origin_id,            null: false
      t.string :city,                                        null: false
      t.string :street_address,                              null: false
      t.string :apartment_name,                              null: false
      t.string :tel,                                         null: false
      t.references :order,                                   null: false, foreign_key: true
      t.timestamps
    end


当初t.references :region_of_shipping_origin_id, null: false,foreign key
と書いておりましたがなぜかマイグレーションができませんでした。

原因はreferences ではなくintegerが正解だったみたい。ちなみに外部キーもいりません!

ちなみに マイグレーションの状況を確認するには
ターミナルにrails db:migrate:statusコマンドでマイグレーションファイルの状況を確認します。

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