0
1

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 5 years have passed since last update.

Railsでプログラムカラムを追加したい時の流れ

Last updated at Posted at 2018-04-21

Railsでプログラム作成済み、カラムを追加したい時の流れ

postテーブル(作成済み)に link, image フィールド追加
アプリ該当フォルダに入りコマンド実行
>rails g migration add_link_to_posts
db-migarateフォルダの上記実行日時のファイル編集
class AddLinkToPosts < ActiveRecord::Migration[5.0]
def change
add_column :posts, :link, :string
add_column :posts, :image, :string
end
end
add部分を追記して保存

ターミナルに戻り
>rails db:migrate 実行

railsコンソールで確認
>rails console
>Post.column_names
でカラム追加確認
>Post.all
でデータ確認
>exit
でコンソール終了
またこれをヘロクにアップロードする方法の次回書きます。
(マイページにはすでに書いてます)
マイページ
#Ruby Rails #プログラム

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?