mysql报错[Field 'id' doesn't have a default value]

一、插入数据时存在错误
Field ‘id‘ doesn‘t have a default value

二、错误分析

1.首先检查数据库设计的主键是否为Int 类型

2.如果是Int 类型检查数据库中设置是否为自增

三、解决办法‘
mysql报错[Field 'id' doesn't have a default value]

四、完美解决
创建数据表:
```
`DROP TABLE IF EXISTS tb_user;
CREATE TABLE tb_user(

id char(32) NOT NULL,
user_name VARCHAR(32)DEFAULT null,
PASSWORD VARCHAR(32) DEfault null,
name VARCHAR(32)DEFAULT null,
age int(10)DEFAULT null,
sex int(2)DEFAULT null,
birthday date DEFAULT null,
created datetime DEFAULT null,
updated datetime DEFAULT null,
PRIMARY KEY(id)
    )ENGINE=INNODB DEFAULT CHARSET=UTF8;`


  插入数据
       `INSERT INTO ssmdemo.tb_user ( user_name, `PASSWORD`, `name`, age, sex, birthday, created, updated )
        VALUES
	(
		‘zpc‘,
		‘12234‘,
		‘城城‘,
		‘22‘,
		‘1‘,
		‘1995-01-3‘,
	        SYSDATE(),
	        SYSDATE());`

mysql报错[Field 'id' doesn't have a default value]

上一篇:MySQL游标实例


下一篇:linux内核hello world模块编写