हर बार जब मैं rake db:migrate
रेल चलाता हूं तो मेरी schema.rb फ़ाइल को बदलने का निर्णय लेता है। कुछ मामलों में यह पूरी तरह से उचित है, हालांकि कुछ अन्य मामलों में ऐसा लगता है कि यह किसी भी कारण से नहीं कर रहा है। जिस मामले में मैं उलझन में हूं, वह है जब मैं एक नया माइग्रेशन खींचता हूं और git से schema.rb का एक नया संस्करण खींचता हूं, और फिर rake db:migrate
चलाता हूं। चूंकि schema.rb फ़ाइल का नया संस्करण इस माइग्रेशन के साथ आया था, इसलिए मुझे schema.rb को अपडेट नहीं करना चाहिए। हालांकि, रेलवे हर बार, इसे बदलती है। जब ऐसा होता है मैं इस तरह के रूप अविश्वसनीय रूप से मूर्ख परिवर्तन पाते हैं:रेल कोई कारण नहीं के लिए schema.rb बदलता है
add_index "my_table", ["column1", "column2"], :name => "index_on_some_columns"
जब ऐसा होता है मैं बस git checkout db/schema.rb
चलाने के लिए और अपने जीवन के साथ पर जाने के
add_index "my_table", ["column2", "column1"], :name => "index_on_some_columns"
, लेकिन यह मुझे कोई अंत नहीं करने के लिए irkes। क्या ऐसा कोई कारण है कि यह ऐसा क्यों करता है, और मैं इसे करने से कैसे रोक सकता हूं?
संपादित करें: यहाँ एक diff
@@ -165,12 +165,11 @@ ActiveRecord::Schema.define(:version => 20130206001907) do
t.column "updated_at", :datetime
- t.column "coordinates", :point, :srid => 4326
@@ -200,15 +199,16 @@ ActiveRecord::Schema.define(:version => 20130206001907) do
t.column "something", :boolean
+ t.column "coordinates", :point, :srid => 4326
+ t.column "random_string", :string
t.column "remote", :string
- t.column "random_string", :string
end
- add_index "my_table", ["id", "foreign_id"], :name => "index_active_my_table_on_foreign_and_id"
- add_index "my_table", ["id", "active"], :name => "index_my_table_on_active_and_id"
- add_index "my_table", ["id", "content_modified_at"], :name => "index_my_table_on_content_modified_at_and_id"
+ add_index "my_table", ["foreign_id", "id"], :name => "index_active_my_table_on_foreign_and_id"
+ add_index "my_table", ["active", "id"], :name => "index_my_table_on_active_and_id"
+ add_index "my_table", ["content_modified_at", "id"], :name => "index_my_table_on_content_modified_at_and_id"
यह सूचकांक आपकी माइग्रेशन फ़ाइलों में कैसे परिभाषित किया गया है? – Novae
अपने diffs – cbrulak
पोस्ट करें कई मामलों में माइग्रेशन ने कहा 'add_index: my_table, ["column2", "column1"] 'लेकिन git के माध्यम से प्रदान की गई schema.rb के विपरीत क्रम में था:' add_index" my_table ", [" column1 ", "कॉलम 2"] '। ऐसा लगता है कि यह सुसंगत प्रतीत होता है, लेकिन अब मैं सोच रहा हूं कि स्तंभों के विपरीत क्रम ने इसे कोड में कैसे बनाया है। यह भद्दा हो सकता है लेकिन क्या लिनक्स/मैक दोनों के साथ काम करने के साथ इसका कुछ संबंध हो सकता है? – wesdotcool