Languages/SQL

[Error] Invalid use of NULL value

잔망루피 2021. 8. 6. 18:36
반응형
Invalid use of NULL value

column을 not null로 제약 조건을 변경하려고 했더니 생긴 에러

이 문제의 원인은 해당 column이 현재 null 값을 가지고 있기 때문이다.

update문으로 null값에 임의의 값을 넣어준다.

update 테이블명 set 컬럼명=값 where 컬럼명 is null;

그 후 not null로 변경하면 성공

 alter table 테이블명 modify column 컬럼명 타입 not null;

 

 

 

참고

https://stackoverflow.com/questions/22971586/mysql-alter-table-causes-error-invalid-use-of-null-value/22971654

 

MySQL Alter table causes Error: Invalid use of NULL value

My existing table: +-----------------+---------------+------+-----+---------+-------------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+...

stackoverflow.com

 

반응형