{"id":7610,"date":"2022-01-02T06:44:41","date_gmt":"2022-01-01T21:44:41","guid":{"rendered":"https:\/\/yumishin.com\/?p=7610"},"modified":"2022-01-02T06:44:41","modified_gmt":"2022-01-01T21:44:41","slug":"rails-add-column","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=7610","title":{"rendered":"Rails\u3067\u30c6\u30fc\u30d6\u30eb\u306b\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Rails\u306e\u30ab\u30e9\u30e0\u64cd\u4f5c\u306f\u3088\u304f\u884c\u3046\u64cd\u4f5c\u306e\u3072\u3068\u3064\u3067\u3059\u304c\u3001\u3053\u3068\u3042\u308b\u3054\u3068\u306b\u5fd8\u308c\u3066\u3057\u307e\u3063\u3066\u3044\u3066\u6bce\u56de\u8abf\u3079\u308b\u306e\u3067\u3001\u307e\u3068\u3081\u3066\u304a\u304d\u305f\u3044\u3068\u304a\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-0\">Rails\u3067\u30c6\u30fc\u30d6\u30eb\u306b\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5<\/h2>\n<h3 id=\"i-1\">\u7d50\u8ad6<\/h3>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30ab\u30e9\u30e0\u3092\u4f5c\u6210\u3059\u308b\u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>rails g migration Add\u30ab\u30e9\u30e0\u540dTo\u30c6\u30fc\u30d6\u30eb\u540d \u30ab\u30e9\u30e0\u540d:\u30c7\u30fc\u30bf\u578b<\/code><\/pre>\n<\/div>\n<p>\u4f8b\u3048\u3070\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p><code>User<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u30e6\u30fc\u30b6\u30fc\u306e\u540d\u524d\u3092\u4fdd\u5b58\u3059\u308b\u30ab\u30e9\u30e0\u3092\u4f5c\u308b\u5834\u5408<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> User\u30c6\u30fc\u30d6\u30eb\u306bname\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>rails g migration AddNameToUser name:string<\/code><\/pre>\n<\/div>\n<h3 id=\"i-2\">\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u5b9f\u969b\u306b\u30ab\u30e9\u30e0\u4f5c\u6210\u3057\u305f\u6642\u306e\u30b3\u30fc\u30c9<\/h3>\n<p>\u4ee5\u4e0b\u306f<code>HogeTask<\/code>\u30c6\u30fc\u30d6\u30eb\u306b<code>title<\/code>\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3057\u305f\u3068\u304d\u306e\u30bf\u30fc\u30df\u30ca\u30eb\u306e\u60c5\u5831\u3067\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30bf\u30fc\u30df\u30ca\u30eb<\/span><\/p>\n<pre><code>$ rails g migration AddTitleToHogeTask title:string #HogeTask\u30c6\u30fc\u30d6\u30eb\u306btitle\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9\u3067\u3059\nRunning via Spring preloader in process 5419\n      invoke  active_record\n      create    db\/migrate\/20220101211538_add_title_to_hoge_task.rb\n\n$ cat db\/migrate\/20220101211538_add_title_to_hoge_task.rb #\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u3092\u78ba\u8a8d\nclass AddTitleToHogeTask &lt; ActiveRecord::Migration[6.1] \n\u3000\u3000\u3000\u3000def change \n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000add_column :hoge_tasks, :title, :string \n\u3000\u3000\u3000\u3000end \nend \n$ rails db:migrate #\u3053\u308c\u3067\u5909\u66f4\u3092\u53cd\u6620\u3055\u305b\u307e\u3059\nRunning via Spring preloader in process 5463 == 20220101211538 AddTitleToHogeTask: migrating =============================== -- add_column(:hoge_tasks, :title, :string) -&gt; 0.0023s\n== 20220101211538 AddTitleToHogeTask: migrated (0.0024s) ======================\n\n$ cat db\/schema.rb #schema\u30d5\u30a1\u30a4\u30eb\u3067\u30ab\u30e9\u30e0\u304c\u3061\u3083\u3093\u3068\u3067\u304d\u3066\u3044\u308b\u304b\u78ba\u8a8d                                 \n# This file is auto-generated from the current state of the database. Instead\n# of editing this file, please use the migrations feature of Active Record to\n# incrementally modify your database, and then regenerate this schema definition.\n#\n# This file is the source Rails uses to define your schema when running `bin\/rails\n# db:schema:load`. When creating a new database, `bin\/rails db:schema:load` tends to\n# be faster and is potentially less error prone than running all of your\n# migrations from scratch. Old migrations may fail to apply correctly if those\n# migrations use external dependencies or application code.\n#\n# It's strongly recommended that you check this file into your version control system.\n\nActiveRecord::Schema.define(version: 2022_01_01_211538) do\n\n  create_table \"hoge_tasks\", force: :cascade do |t|\n    t.string \"name\"\n    t.text \"content\"\n    t.datetime \"created_at\", precision: 6, null: false\n    t.datetime \"updated_at\", precision: 6, null: false\n    t.string \"title\"\u3000#\u2190\u65b0\u3057\u304f\u30ab\u30e9\u30e0\u304c\u3067\u304d\u3066\u307e\u3059\uff01\n  end\n\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Rails\u306e\u30ab\u30e9\u30e0\u64cd\u4f5c\u306f\u3088\u304f\u884c\u3046\u64cd\u4f5c\u306e\u3072\u3068\u3064\u3067\u3059\u304c\u3001\u3053\u3068\u3042\u308b\u3054\u3068\u306b\u5fd8\u308c\u3066\u3057\u307e\u3063\u3066\u3044\u3066\u6bce\u56de\u8abf\u3079\u308b\u306e\u3067\u3001\u307e\u3068\u3081\u3066\u304a\u304d\u305f\u3044\u3068\u304a\u601d\u3044\u307e\u3059\u3002 Rails\u3067\u30c6\u30fc\u30d6\u30eb\u306b\u30ab\u30e9\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u65b9\u6cd5 \u7d50\u8ad6 \u4f8b\u3048\u3070\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3044\u307e\u3059\u3002  &#8230; <\/p>\n","protected":false},"author":1,"featured_media":7613,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[272],"tags":[],"class_list":{"0":"post-7610","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-programing","8":"entry"},"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7610"}],"version-history":[{"count":3,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7610\/revisions"}],"predecessor-version":[{"id":7615,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7610\/revisions\/7615"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/7613"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}