LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】マイグレーションファイルで作ったテーブルヘッダーを確認する方法

Last updated at Posted at 2021-05-08

ヘッダー確認方法

マイグレーションファイルでテーブルを作成した時に、seedでデータを作成する際にテーブルヘッダー名を確認する方法をご紹介します。

railsコンソールで確認

Railsコンソールを起動し、対象のインスタンスを作成することで、カラムが確認できます。

ターミナル
#Railsコンソールを起動
rails c

#対象のインスタンスを作ることで、カラムが確認できます
User.new
   (50.1ms)  SELECT sqlite_version(*)
=> #<User id: nil, name: nil, email: nil, password: nil, address: nil,created_at: nil, updated_at: nil>

schemaファイルで確認

migrateファイルと同じディレクトリにあるschema.rbファイルでヘッダー名を確認できます。

schema.rb
ActiveRecord::Schema.define(version: 2021_05_06_105214) do

  create_table "users", force: :cascade do |t|
    t.string "name", null: false
    t.string "email", null: false
    t.string "password", null: false
    t.text "address"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

end

参考

unknown attribute '○○○○' for ○○○. →カラムのリネーム
https://qiita.com/Ayaka_ramens/items/f0c68b08fcf6145c2b17

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