Set Warnings error

Say, get warnings on executing of query like this and similar to it: "Warning 1364 Field 'D_STAFF_1' doesn't have a default value" .Any ideas please?

This is the create statement:

CREATE TABLE `zSHIFTTEMP` (
   `COMPANY` varchar(5) NOT NULL DEFAULT '',
   `ShiftNo` int(11) DEFAULT NULL,
	`D_STAFF_1` VARCHAR(20) NOT NULL,
	`D_STAFF_2` VARCHAR(20) NOT NULL,
	`D_STAFF_3` VARCHAR(20) NOT NULL,
	`D_STAFF_4` VARCHAR(20) NOT NULL,
	`D_STAFF_5` VARCHAR(20) NOT NULL,
	`D_STAFF_6` VARCHAR(20) NOT NULL,
	`D_STAFF_7` VARCHAR(20) NOT NULL,
	`D_STAFF_8` VARCHAR(20) NOT NULL,
	`D_STAFF_9` VARCHAR(20) NOT NULL,
	`D_STAFF_10` VARCHAR(20) NOT NULL,
	`D_SUPERVISOR` VARCHAR(20) NOT NULL,
	`N_STAFF_1` VARCHAR(20) NOT NULL,
	`N_STAFF_2` VARCHAR(20) NOT NULL,
	`N_STAFF_3` VARCHAR(20) NOT NULL,
	`N_STAFF_4` VARCHAR(20) NOT NULL,
	`N_STAFF_5` VARCHAR(20) NOT NULL,
	`N_STAFF_6` VARCHAR(20) NOT NULL,
	`N_STAFF_7` VARCHAR(20) NOT NULL,
	`N_STAFF_8` VARCHAR(20) NOT NULL,
	`N_STAFF_9` VARCHAR(20) NOT NULL,
	`N_STAFF_10` VARCHAR(20) NOT NULL,
	`N_SUPERVISOR` VARCHAR(20) NOT NULL,
  `PumpNo` int(11) DEFAULT NULL,
  `OFF2` double DEFAULT NULL,
  `OFF1` double DEFAULT NULL,
  `ON1` double DEFAULT NULL,
  `Grade` varchar(15) DEFAULT NULL,
  `Tank` int(11) DEFAULT NULL,
  `DIPSOFF` double DEFAULT NULL,
  `GradeTank` varchar(30) DEFAULT NULL,
  `DIPSON` double DEFAULT NULL,
  `LITRES_FUEL_DELIVERY` double DEFAULT NULL,
  `BEFORE_FUEL_DELIVERY` double DEFAULT NULL,
  `AFTER_FUEL_DELIVERY` double DEFAULT NULL,
  `INVOICE_NO_FUEL_DELIVERY` varchar(15) DEFAULT NULL,
  `SUPERVISOR_FUEL_DELIVERY` varchar(15) DEFAULT NULL,
  `ShiftStock1` int(11) DEFAULT NULL,
  `CodeStock` varchar(15) DEFAULT NULL,
  `DescStock` varchar(50) DEFAULT NULL,
  `ONStock1` int(11) NULL,
  `ISSUE1` int(11) NULL,
  `OFFStock1` int(11) NULL,
  `SALES1` int(11) NULL,
  `MONEY1` double NULL,
  `ShiftStock2` int(11) NULL,
  `ONStock2` int(11) NULL,
  `ISSUE2` int(11) NULL,
  `OFFStock2` int(11) NULL,
  `SALES2` int(11) NULL,
  `MONEY2` double NULL,
  `RowPos` int(11) DEFAULT NULL,
  `GroupStock` varchar(10) DEFAULT NULL,
  `LESS_SPEEDPOINTS` double DEFAULT NULL,
  `BANK_TOTAL` double DEFAULT NULL,
  `--CASH_CONNECT_VENDOR--` varchar(15)  NOT NULL,
  `SHIFTNO_CASH_CONNECT` varchar(15)  NOT NULL,
  `CASH_CONNECT_BAG_NO` varchar(15)  DEFAULT NULL,
  `CASH_CONNECT_CASH` double DEFAULT NULL,
  `D_CASH_RECEIVED` DOUBLE NULL DEFAULT NULL,
  `N_CASH_RECEIVED` DOUBLE NULL DEFAULT NULL,
  `Payout_Description` VARCHAR(50) NULL DEFAULT NULL,
  `Payout_Amount` DOUBLE NOT NULL DEFAULT '0',    
  `ShiftNoTank` int(11) DEFAULT NULL,
  `AutoKeyTank` int(11) DEFAULT NULL,
  `AutoKey` int(11) NOT NULL AUTO_INCREMENT,

  PRIMARY KEY (`AutoKey`,`COMPANY`),
  KEY `ShiftNo` (`ShiftNo`)
)ENGINE=MyISAM AUTO_INCREMENT=1321 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

Open in new window

shaunwinginAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
That warning is raised due to your STRICT_TRANS_TABLES setting held in the my.ini file*

STRICT_TRANS_TABLES

Enable strict mode for transactional storage engines, and when possible for nontransactional storage engines. Additional details follow.

Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.)

For statements that do not change data, such as SELECT, invalid values generate a warning in strict mode, not an error.
* location of this will depend on version, but see this for v5.6 (similar pages exist for other versions)
http://dev.mysql.com/doc/refman/5.6/en/option-files.html

OR: supply a default against for field :)
0
shaunwinginAuthor Commented:
tx. Pls assist with assigning the default. MySQL ver 5.1
0
PortletPaulfreelancerCommented:
There are really 2 options:
a. add a default value, or
b. remove the NOT NULL constraint

I'm not in a position to tell you which is the best option for each affected field, so I'll provide an example of both, using MySQL 5.5.32 at sqlfiddle but the syntax should be the same in your version:
**MySQL 5.5.32 Schema Setup**:

    CREATE TABLE `zSHIFTTEMP` (
       `COMPANY` varchar(5) NOT NULL DEFAULT '',
       `ShiftNo` int(11) DEFAULT NULL,
    	`D_STAFF_1` VARCHAR(20) NOT NULL,
    	`D_STAFF_2` VARCHAR(20) NOT NULL,
    	`D_STAFF_3` VARCHAR(20) NOT NULL,
    	`D_STAFF_4` VARCHAR(20) NOT NULL
      )
    ;
    
    /* add defualt */
    ALTER TABLE zSHIFTTEMP
    CHANGE `D_STAFF_1` `D_STAFF_1` VARCHAR(20) NOT NULL DEFAULT ''
    ;
    
    /* remove NOT NULL */
    ALTER TABLE zSHIFTTEMP
    CHANGE `D_STAFF_2` `D_STAFF_2` VARCHAR(20)
    ;
    
    
    SHOW CREATE TABLE zSHIFTTEMP
; 
    
    

and: a sample query of the schema

    SELECT
            TABLE_NAME	
          , COLUMN_NAME	
          , ORDINAL_POSITION	
          , COLUMN_DEFAULT	
          , IS_NULLABLE	
          , DATA_TYPE
    FROM `INFORMATION_SCHEMA`.`COLUMNS` 
    WHERE  `TABLE_NAME`='zSHIFTTEMP'
    

**[Results]**:
    
    | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE |
    |------------|-------------|------------------|----------------|-------------|-----------|
    | zshifttemp |     COMPANY |                1 |                |          NO |   varchar |
    | zshifttemp |     ShiftNo |                2 |         (null) |         YES |       int |
    | zshifttemp |   D_STAFF_1 |                3 |                |          NO |   varchar |
    | zshifttemp |   D_STAFF_2 |                4 |         (null) |         YES |   varchar |
    | zshifttemp |   D_STAFF_3 |                5 |         (null) |          NO |   varchar |
    | zshifttemp |   D_STAFF_4 |                6 |         (null) |          NO |   varchar |



  [1]: http://sqlfiddle.com/#!2/e2d365/2

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.