Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

sql - Column cannot be null Mysql

Below is my table structure

CREATE TABLE IF NOT EXISTS `physicians` (
  `physician_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) NOT NULL,
  `physician_gender` varchar(10) NOT NULL,
  `physician_dob_date` int(11) NOT NULL,
  `physician_dob_month` int(11) NOT NULL,
  `physician_dob_year` year(4) NOT NULL,
  `physician_profession` varchar(50) NOT NULL,
  `medical_specialty` varchar(100) NOT NULL,
  `medical_school` varchar(100) NOT NULL,
  `traning_year` year(4) NOT NULL,
  `physician_minc` varchar(20) NOT NULL,
  `physician_country` varchar(100) NOT NULL,
  `physician_state` varchar(60) NOT NULL,
  `physician_city` varchar(60) NOT NULL,
  `physician_address` varchar(100) NOT NULL,
  `physician_postal_code` varchar(10) NOT NULL,
  `physician_phone_number` varchar(20) NOT NULL,
  `physician_default_msg` longtext NOT NULL,
  PRIMARY KEY (`physician_id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

I am executing a query and it showing me column can not be null below is my query

INSERT INTO `physicians` (`user_id`, `physician_gender`, `physician_dob_date`, `physician_dob_month`, `physician_dob_year`, `physician_profession`, `medical_specialty`, `medical_school`, `traning_year`, `physician_minc`, `physician_country`, `physician_state`, `physician_city`, `physician_address`, `physician_postal_code`, `physician_phone_number`, `physician_default_msg`) VALUES (4, 'Female', '5', '7', '1955', '3', '2', '1', '1965', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

Error - Column 'physician_minc' cannot be null

physician_minc is not mandatory field. How can I fix this problem ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have defined the not null value to 'physician_minc':

`physician_minc` varchar(20) NOT NULL,

How can you pass the null value to it.First you need to make the physician_minc column as null then only you can pass your desired null value.

`physician_minc` varchar(20) NULL,

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...