검색결과 리스트
글
migration 문법
IT(Old)/RubyOnRails
2008. 1. 21. 15:08
1. 널값 허용X
create_table "groups" do |t|
t.column "name", :string, Lnull => false
end
2. default값 지정
create_table "users" do |t|
t.column "type", :string, Ldefault => "일반"
end
3. 문자열 컬럼 길이 지정
create_table "groups" do |t|
t.column "name", :string, Llimit => 10
end
4. 숫자컬럼 길이지정
create_table "people" do |t|
t.column "name", :string
t.column "height", :decimal, Lprecision => 5, Lscale => 2
end
5. boolean
boolean은 TINYINT로 지정이 되어 true(1), false(2) 로 저장이 된다.
6. 테이블명 변경
rename_table "groups", categories"
7. 인덱스 추가
add_index "groups", "name", :unique => true
remove_index "groups", "name"
8. 기타 SQL
마이그레이션에서 지원하지 않는 비표준 기능은 execute를 사용해라
execute "ALTER TABLE people ADD CONSTRAINT fk_person_group"
create_table "groups" do |t|
t.column "name", :string, Lnull => false
end
2. default값 지정
create_table "users" do |t|
t.column "type", :string, Ldefault => "일반"
end
3. 문자열 컬럼 길이 지정
create_table "groups" do |t|
t.column "name", :string, Llimit => 10
end
4. 숫자컬럼 길이지정
create_table "people" do |t|
t.column "name", :string
t.column "height", :decimal, Lprecision => 5, Lscale => 2
end
5. boolean
boolean은 TINYINT로 지정이 되어 true(1), false(2) 로 저장이 된다.
6. 테이블명 변경
rename_table "groups", categories"
7. 인덱스 추가
add_index "groups", "name", :unique => true
remove_index "groups", "name"
8. 기타 SQL
마이그레이션에서 지원하지 않는 비표준 기능은 execute를 사용해라
execute "ALTER TABLE people ADD CONSTRAINT fk_person_group"