4
yaml을 사용하고 있지만 xml이나 json과 거의 같습니다. addForeignKeyConstraint를 사용할 수 있다는 것을 알았지 만 기존 테이블을 변경하지 않고 테이블 생성시 제약 조건을 추가하려고합니다. 어떻게해야합니까? 이런 식으로 할 수 있을까요?Liquibase에서 외래 키 제약 조건을 사용하여 테이블을 만드는 방법은 무엇입니까?
- changeSet:
id: create_questions
author: Author
changes:
- createTable:
tableName: questions
columns:
- column:
name: id
type: int
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: user_id
type: int
constraints:
foreignKey:
referencedColumnNames: id
referencedTableName: users
nullable: false
- column:
name: question
type: varchar(255)
constraints:
nullable: false
하지만 어디 할 fk_questions_author이 무엇인지 정의하시오. 그것을 정의하기 위해 changeSet을 작성해야합니까? – godzsa
@ godzsa : foreign 키는'references = "users (id)"부분을 통해 정의됩니다. 그것은'users' 테이블의'id' 컬럼을 참조한다는 것을 의미합니다. 그것은 당신이 SQL에서 사용할 문법입니다 :'... foreign key user_id는 사용자 (id)를 참조합니다' –