본문 바로가기

[Terry] DBMS

Invalid default value for 'no' 에러...

계층형 게시판을 구현하기 위해 MySQL 5.0에 아래와 같이 쿼리를 실행시켰다.
create table bbs(
 no int unsigned default '0' auto_increment primary key,
 family int not null,
 orderby int not null,
 step int not null,
 name char(20) not null,
 title varchar(20) not null,
 memo text not null,
 hit int unsigned default '0'
)

그런데 아래와 같은 에러를 발생했다.
Invalid default value for 'no'

이 황당한 시추에이션...ㅋ

구글링해본 결과 MySQL 5버전부터는 default와 auto_increment 를 함께 사용할 수 없다고 한다.
이유는 auto_increment 가 걸린 컬럼은 default 값으로 null만 받아들이고, 다른 어떤값도 받아들이지 않는다고 한다.
그렇기 때문에 default '0'을 삭제해야 문제가 해결된다고 한다.

그래서 수정한 쿼리는 다음과 같다.
create table bbs(
 no int unsigned auto_increment primary key,
 family int not null,
 orderby int not null,
 step int not null,
 name char(20) not null,
 title varchar(20) not null,
 memo text not null,
 hit int unsigned default '0'
)