{"id":1647,"date":"2007-04-25T23:46:31","date_gmt":"2007-04-25T15:46:31","guid":{"rendered":"http:\/\/ihower.idv.tw\/blog\/archives\/1647"},"modified":"2011-04-09T02:11:54","modified_gmt":"2011-04-08T18:11:54","slug":"rails-migrations-rebuild","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/1647-rails-migrations-rebuild","title":{"rendered":"Rails Migrations \u780d\u6389\u91cd\u7df4"},"content":{"rendered":"<p>\u4eca\u5929\u770b <a href=\"http:\/\/pragmaticprogrammer.com\/titles\/rails\/index.html\">AWDwR 2nd. <\/a>\u7b2c16\u7ae0 Migrations \u7684\u6642\u5019\uff0c\u6709\u4e00\u7bc0\u53eb When Migrations Go Bad\uff0c\u610f\u601d\u662f\u8aaa\u82e5\u8dd1 Migrations \u7684\u6642\u5019\u610f\u5916\u6b7b\u6389\uff0c\u4f8b\u5982\u4ee5\u4e0b\u9019\u7a2e\u60c5\u6cc1\uff0ctable one\u597d\u4e86\uff0ctable two\u9084\u6c92&#8230;<\/p>\n<blockquote><p>def self.up do&#8230;<br \/>\n\u00a0 create_table :one do &#8230;<br \/>\n\u00a0 end<br \/>\n\u00a0 create_table :two do..<br \/>\n\u00a0 end<br \/>\nend<\/p>\n<p>def self.down<br \/>\n\u00a0 drop_table :two<br \/>\n\u00a0 drop_table :one<br \/>\nend<\/p><\/blockquote>\n<p>\u6b64\u6642\u8981\u600e\u9ebc\u8655\u7406\u5462? up\u8ddfdown\u9032\u9000\u4e0d\u5f97\u5462\uff0c\u66f8\u4e0a\u7684\u89e3\u6cd5\u5f88\u7c21\u55ae\uff0c\u5c31\u662f<strong>\u780d\u6389\u91cd\u7df4<\/strong>\uff0c\u628a\u5168\u90e8 table drop\u6389\uff0c\u91cd\u65b0\u8dd1\u4e00\u904d rake db:migrate\u3002<\/p>\n<p>\u8b93\u6211\u5370\u8c61\u6df1\u523b\u7684\u662f\u9019\u62db\u6700\u5f8c\u4e00\u7bc0\u53c8\u63d0\u5230\u4e00\u6b21\u3002\u554f\u984c\u662f\u8aaa\u96a8\u8457 migrations \u7684\u7d2f\u9032\uff0c\u6bcf\u500b schema \u5b9a\u7fa9\u53ef\u80fd\u6703\u6563\u4f48\u5728\u5404\u500b migration \u6a94\u6848\u4e2d\uff0c\u6211\u5011<strong>\u8981\u5982\u4f55\u4e00\u773c\u770b\u61c2\u6bcf\u5f35 table \u6700\u5f8c\u5230\u5e95\u6709\u54ea\u4e9b\u6b04\u4f4d?<\/strong><\/p>\n<p>\u65b9\u6cd5\u4e00\u662f\u770b db\/schema.rb \u6a94\uff0c\u6709\u5168\u90e8\u7684\u5b9a\u7fa9(Ruby form)<\/p>\n<p>\u65b9\u6cd5\u4e8c\u662f\u4fdd\u6301\u6bcf\u5f35 table \u53ea\u6709\u552f\u4e00\u7684 migration \u6a94\u6848\uff0c\u6709\u4efb\u4f55\u4fee\u6539\u4e0d\u8981\u65b0\u589e\u518d migration\u6a94\u6848\u4e86\uff0c\u800c\u662f\u7528\u7de8\u8f2f\u7684\u65b9\u5f0f\uff0c\u6bcf\u6b21\u6709\u4fee\u6539\u5c31<strong>\u780d\u6389\u91cd\u7df4<\/strong>\u5373\u53ef\u3002\u8a71\u8aaa\u6b64\u62db\u96d6\u7136\u8ddf Migrations \u7248\u672c\u7d2f\u9032\u7684\u6982\u5ff5\u4e0d\u540c\uff0c\u4f46\u4e5f\u662f\u53ef\u4ee5work\u3002<\/p>\n<p>\u65b9\u6cd5\u4e09\u662f\u88dd <a href=\"http:\/\/agilewebdevelopment.com\/plugins\/annotate_models\">annotate_models plugin<\/a>\uff0c\u6bcf\u6b21\u6709\u8b8a\u52d5\u4f60\u53ea\u8981\u8dd1 rake annotate_models\uff0c\u4ed6\u5c31\u6703\u5728\u4f60\u7684 model \u81ea\u52d5\u52a0\u4e0a table column \u8a3b\u89e3\uff0c\u4e00\u76ee\u77ad\u7136\u3002\u7528\u6cd5\u8ddf\u7d50\u679c\u53ef\u4ee5<a href=\"http:\/\/midnightrubyist.blogspot.com\/2007\/04\/annotate-models.html\">\u53c3\u8003\u9019\u7bc7<\/a>\u3002<\/p>\n<p>\u984c\u5916\u8a71\uff0c\u4eca\u5929\u7cfb\u4e0a\u6709\u67d0\u8001\u5e2b\u9032\u4e0d\u53bbopenwebmail\uff0c\u767b\u5165\u5f8c\u5410 Internal error\uff0c\u6211\u8ddf\u96fb\u8166\u52a9\u7406\u6700\u5f8c\u7684\u89e3\u6cd5\u4e5f\u662f\u780d\u6389\u91cd\u7df4&#8230; :p (\u6709\u7a2e\u5f88\u905c\u7684\u611f\u89ba)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u770b AWDwR 2nd. \u7b2c16\u7ae0 Migrations \u7684\u6642\u5019\uff0c\u6709\u4e00\u7bc0\u53eb When Migrations &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/1647-rails-migrations-rebuild\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Rails Migrations \u780d\u6389\u91cd\u7df4\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[38,53],"tags":[],"class_list":["post-1647","post","type-post","status-publish","format-standard","hentry","category-database","category-rails","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-qz","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=1647"}],"version-history":[{"count":1,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1647\/revisions"}],"predecessor-version":[{"id":5576,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1647\/revisions\/5576"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=1647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=1647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=1647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}