{"id":317,"date":"2007-06-20T20:17:17","date_gmt":"2007-06-20T11:17:17","guid":{"rendered":"https:\/\/wp-78qb7hnp.pistolfly.jp\/weblog\/2007\/06\/migrationforeign-key.html"},"modified":"2016-07-16T11:23:45","modified_gmt":"2016-07-16T02:23:45","slug":"migrationforeign-key","status":"publish","type":"post","link":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html","title":{"rendered":"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b"},"content":{"rendered":"<p><a title=\"UsingMigrations in Ruby on Rails\" href=\"http:\/\/wiki.rubyonrails.org\/rails\/pages\/UsingMigrations\">UsingMigrations in Ruby on Rails<\/a><\/p>\n<pre class=\"prettyprint\">class CreateLineItems &lt; ActiveRecord::Migration\r\n  def self.up\r\n    create_table(:line_items) do |t|\r\n      t.column(:product_id, :integer, :null =&gt; false)\r\n      t.column(:quantity, :integer, :null =&gt; false, :default =&gt; 0)\r\n    end\r\n    # This line is required if you're running a version of MySQL prior to 4.1.2\r\n    #add_index(:line_items, [:product_id], :name =&gt; 'fk_line_items_product')\r\n    execute('ALTER TABLE line_items ADD CONSTRAINT fk_line_items_product FOREIGN KEY ( product_id ) REFERENCES products( id ) ')\r\n  end\r\n  def self.down\r\n    drop_table(:line_items)\r\n  end\r\nend<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>UsingMigrations in Ruby on Rails class CreateLineItems &lt; ActiveRecord::Migration def self.up create_table(: &hellip; <a href=\"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"317","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[31],"tags":[],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-ruby-on-rails","ja"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b - Pistolfly<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b - Pistolfly\" \/>\n<meta property=\"og:description\" content=\"UsingMigrations in Ruby on Rails class CreateLineItems &lt; ActiveRecord::Migration def self.up create_table(: &hellip; \u7d9a\u304d\u3092\u8aad\u3080 migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html\" \/>\n<meta property=\"og:site_name\" content=\"Pistolfly\" \/>\n<meta property=\"article:published_time\" content=\"2007-06-20T11:17:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-07-16T02:23:45+00:00\" \/>\n<meta name=\"author\" content=\"Pistolfly\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pistolfly\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html\"},\"author\":{\"name\":\"Pistolfly\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\"},\"headline\":\"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b\",\"datePublished\":\"2007-06-20T11:17:17+00:00\",\"dateModified\":\"2016-07-16T02:23:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html\"},\"wordCount\":8,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\"},\"articleSection\":[\"Ruby on Rails\"],\"inLanguage\":\"ja\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html\",\"url\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html\",\"name\":\"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b - Pistolfly\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#website\"},\"datePublished\":\"2007-06-20T11:17:17+00:00\",\"dateModified\":\"2016-07-16T02:23:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/2007\\\/06\\\/migrationforeign-key.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u30db\u30fc\u30e0\",\"item\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#website\",\"url\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/\",\"name\":\"Pistolfly\",\"description\":\"Developer Blog\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\",\"name\":\"Pistolfly\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\",\"caption\":\"Pistolfly\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\"},\"description\":\"Software Engineer in Tokyo, Japan\",\"url\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/author\\\/pistolfly\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b - Pistolfly","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html","og_locale":"ja_JP","og_type":"article","og_title":"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b - Pistolfly","og_description":"UsingMigrations in Ruby on Rails class CreateLineItems &lt; ActiveRecord::Migration def self.up create_table(: &hellip; \u7d9a\u304d\u3092\u8aad\u3080 migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b &rarr;","og_url":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html","og_site_name":"Pistolfly","article_published_time":"2007-06-20T11:17:17+00:00","article_modified_time":"2016-07-16T02:23:45+00:00","author":"Pistolfly","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"Pistolfly"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html#article","isPartOf":{"@id":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html"},"author":{"name":"Pistolfly","@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab"},"headline":"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b","datePublished":"2007-06-20T11:17:17+00:00","dateModified":"2016-07-16T02:23:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html"},"wordCount":8,"publisher":{"@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab"},"articleSection":["Ruby on Rails"],"inLanguage":"ja"},{"@type":"WebPage","@id":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html","url":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html","name":"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b - Pistolfly","isPartOf":{"@id":"https:\/\/www.pistolfly.com\/weblog\/#website"},"datePublished":"2007-06-20T11:17:17+00:00","dateModified":"2016-07-16T02:23:45+00:00","breadcrumb":{"@id":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pistolfly.com\/weblog\/2007\/06\/migrationforeign-key.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u30db\u30fc\u30e0","item":"https:\/\/www.pistolfly.com\/weblog"},{"@type":"ListItem","position":2,"name":"migration\u3067foreign key\u3092\u5b9a\u7fa9\u3059\u308b"}]},{"@type":"WebSite","@id":"https:\/\/www.pistolfly.com\/weblog\/#website","url":"https:\/\/www.pistolfly.com\/weblog\/","name":"Pistolfly","description":"Developer Blog","publisher":{"@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pistolfly.com\/weblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab","name":"Pistolfly","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g","caption":"Pistolfly"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g"},"description":"Software Engineer in Tokyo, Japan","url":"https:\/\/www.pistolfly.com\/weblog\/author\/pistolfly"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paorzz-57","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":3,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":3552,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts\/317\/revisions\/3552"}],"wp:attachment":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}