설명해 드리겠습니다.유해한 결과없이 마이그레이션 파일을 혼합 할 수 있습니까?
나는 M. Hartl tutorial을 따라 갔고 나는 그 사람을 마이그레이션하는 것을 좋아했습니다. 그래서 지금, 나는/디렉토리를 마이그레이션 (나는 당신에게 타임 스탬프를 아끼지) 내 DB에 다음 파일이 :
create_users.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps
end
end
end
add_index_to_users_email.rb
class AddIndexToUsersEmail < ActiveRecord::Migration
def change
add_index :users, :email, unique: true
end
end
add_password_digest_to_users.rb
class AddPasswordDigestToUsers < ActiveRecord::Migration
def change
add_column :users, :password_digest, :string
end
end
add_remember_token_to_users.rb
class AddRememberTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :remember_token, :string
add_index :users, :remember_token
end
end
add_admin_to_users.rb
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: false
end
end
은 가능한 다음과 같이 create_users.rb에 모든 것을 혼합하고, 다른 사람의 마이그레이션을 삭제하는 것입니다 내 애플 리케이션에 손상없이 파일?
create_users.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest
t.string :remember_token
t.boolean :admin, default: false
t.timestamps
end
add_index :users, :email, unique: true
add_index :users, :remember_token
end
end
고맙습니다! 나는 생산에 있지 않으므로 아무런 해를 입지 않았다! –
때때로 rake db : migrate 이전에 schema.rb를 삭제하면 유용합니다. 기본적으로 rake db : migrate는 새로운 schema.rb를 생성합니다. 특히 마이그레이션 파일에서 필드와 데이터베이스 구조를 수정하는 경우. – Zoltan