레일을 실행할 때마다 rake db:migrate
레일즈가 내 schema.rb 파일을 변경할 것을 결정합니다. 어떤 경우에는 이것이 완전히 합리적이지만 어떤 다른 경우에는 아무 이유없이 그것을하는 것처럼 보입니다. 내가 혼란스러워하는 경우는 새 이주와 git에서 schema.rb의 새 버전을 가져온 다음 rake db:migrate
을 실행하는 것입니다. schema.rb 파일의 새 버전이이 마이그레이션과 함께 제공되므로 schema.rb를 업데이트하면 안됩니다. 그러나 레일은 매번 변경됩니다. 이 경우 I는 다음과 같은 믿을 수 없을만큼 바보 변경 찾을 :레일스는 아무 이유없이 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. 왜 그렇게하는지, 어떻게하면 멈추게 할 수 있습니까?
편집 : schema.rb 파일의 새 버전이 마이그레이션와 함께, 내가 schema.rb를 업데이트하지 않아야하기 때문에 여기에 발췌가 사랑하는
@@ -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" "column2"]'. 일관성이있는 것 같지만, 이제는 컬럼의 반대 순서가 어떻게 코드를 만들었는지 궁금합니다. 이것은 순진 할 수도 있지만 이것은 linux/mac와 함께 작업하는 것과 관련이있을 수 있습니까? – wesdotcool