1
0

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 1 year has passed since last update.

データベース上のテーブル名とカラムデータを確認する方法(Ruby on Rails)

Last updated at Posted at 2022-03-11

(開発環境:Ruby3.1.0 Rails7.0.2.2)

まずはターミナルで確認したいアプリケーションディレクトリに移動(ディレクトリの移動方法:cd 1階層下のディレクトリ名)

ターミナル
ディレクトリ名% rails c #Railsコンソール起動
irb(main):001:0> 確認したいデータのモデル名.all

これで以下のようにテーブル名とカラムデータの内容が確認できます。

ターミナル
 (1.8ms)  SELECT sqlite_version(*)
  モデル名 Load (0.3ms)  SELECT "テーブル名".* FROM "テーブル名" 
id: 1, #自動生成                                                           
  name: nil, #任意に生成したデータ名(データ名は(例)namenilは値が何もないという表記)                                                                                                           
  created_at: Mon, 28 Feb 2022 21:49:47.896089000 UTC +00:00, #自動生成     
  updated_at: Mon, 28 Feb 2022 21:49:47.896089000 UTC #自動生成
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?