호비시의 끄적끄적

JPA에서 String length 변경 본문

Back/Spring

JPA에서 String length 변경

호비시 2022. 3. 22. 14:01

항해99 Spring 주특기 1주차 개인과제를 하면서 겪은 문제이다.

 

초기에 table setting 을 이런식으로 해주고

@Getter
@Entity
@NoArgsConstructor
public class Task extends Timestamped {

    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    private Long id;

    @Column(nullable = false)
    private String title;
    @Column(nullable = false)
    private String author;
    @Column(nullable = false)
    private String content;
}

데이터를 넣은 후 잘 작동하는 것을 확인했다.

 

하지만 추후에 content의 길이가 길어져야 한다는 필요성을 깨닫고

content의 길이를 늘리고자 이것저것 구글링을 하기 시작했는데...

 

@Getter
@Entity
@NoArgsConstructor
public class Task extends Timestamped {

    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    private Long id;

    @Column(nullable = false)
    private String title;
    @Column(nullable = false)
    private String author;
    @Column(length=1000, nullable = false)
    private String content;
}

@Column(length= 1000, nullable = false)를 추가하면 된다는 어느 블로그의 글을 보고 따라해 보았지만

긴 content를 넣을 수 없었다.

 

이런저런 고민을 한 결과

 

이미 선언된 table에 대해서는 이 방법으론 바꿀 수 없었다.

그래서 table을 drop한 뒤에 다시 서버를 실행시키니 length = 1000이 잘 작동되었다.

data가 들어간 상태에서 varchar의 길이를 늘리는 방법이 있는지 찾아봐야겠다

'Back > Spring' 카테고리의 다른 글

테스트 종류별 특징  (0) 2022.03.25
Transaction  (0) 2022.03.22
EC2 시간 설정  (0) 2022.03.22
Spring 구조 간단 요약  (0) 2022.03.19
Java Spring 기본 설정  (0) 2022.03.18
Comments