Column cannot be null Mysql

前端 未结 8 1748
广开言路
广开言路 2020-12-21 05:12

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,
         


        
相关标签:
8条回答
  • 2020-12-21 05:39

    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,
    
    0 讨论(0)
  • 2020-12-21 05:40

    Update your table as this:

    ALTER TABLE `physicians` 
    CHANGE `physician_minc` `physician_minc` VARCHAR(20) CHARACTER 
    SET latin1 COLLATE latin1_swedish_ci NULL;
    
    0 讨论(0)
  • 2020-12-21 05:44

    The last values of your insertion are NULL yet declared as not null in the table creation, hence the error. If physician_minc is not mandatory then allow it to be NULL in the table creation by replacing physician_minc varchar(20) NOT NULL, into physician_minc varchar(20) NULL,

    0 讨论(0)
  • 2020-12-21 05:48

    Don't define physician_minc as not null

    0 讨论(0)
  • 2020-12-21 05:48

    Unlike your query this query will substitute an empty string for null if the columns do not support null values.:

    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`) SELECT 4, 'Female', '5', '7', '1955', '3', '2', '1', '1965', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL;
    
    0 讨论(0)
  • 2020-12-21 05:50

    ALTER TABLE physicians CHANGE `physician_minc` `physician_minc` VARCHAR(20) NULL;

    0 讨论(0)
提交回复
热议问题