#1067 - Invalid default value for 'LastUpdated' - mysql

I made my ER diagram via MySQL WorkBench and exported it as a sql. Below is code for one table.
CREATE TABLE IF NOT EXISTS `xxx`.`Agent` (
`idAgent` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(100) NOT NULL,
`RegistrationNumber` VARCHAR(45) NOT NULL,
`RegistrationDate` DATE NULL,
`DateOfDealStart` DATE NULL,
`AddressLine1` VARCHAR(100) NULL,
`AddressLine2` VARCHAR(100) NULL,
`Country` VARCHAR(45) NULL,
`CurrentStatus` TINYINT(1) NOT NULL,
`DateCreated` TIMESTAMP NOT NULL,
`LastUpdated` TIMESTAMP NOT NULL,
PRIMARY KEY (`idAgent`))
ENGINE = InnoDB;
However when I am trying to import the script into MySQL via PhpMyAdmin, it says below.
#1067 - Invalid default value for 'LastUpdated'
I have not provided any default value, so how can it could be "Invalid"?

Related

MySQL Import CSV (Row import failed with error: ("Incorrect datetime value: '' for column 'Escalation_date' at row 1", 1292)

I've exported some rows from a table in order to simulate a Import from CSV into MySQL Table.
Rows are like this:
Number;Opened;Opened by;Source;Caller;Location;Category;Subcategory;Priority;Incident state;On hold reason;Assignment group;Support vendor name;ID vendor ticket;Escalation date;Parent Incident;Problem;Resolved;Resolved by;Closed;Closure CI;CI Closure Code;Sub CI;Sub Closure CI;Resolve time;Duration
INC0028837;2019-01-02 07:01:35;User1;Portal;User2;Location1;Category1;Sub_Cat1;3 - Moderate;Closed;;Assignment1;;;;;;2019-01-02 09:43;Resolved1;2019-01-05 10:00:00;;;;;9742;9742
I made some stored procedure that will update last columns when called.
My DB structure is as follows:
CREATE TABLE `incident_raw_data` (
`Number` varchar(12) NOT NULL,
`Opened` datetime DEFAULT NULL,
`Opened_by` varchar(45) DEFAULT NULL,
`Source` varchar(12) DEFAULT NULL,
`Caller` varchar(25) DEFAULT NULL,
`Location` varchar(25) DEFAULT NULL,
`Category` varchar(45) DEFAULT NULL,
`Subcategory` varchar(25) DEFAULT NULL,
`Priority` varchar(12) DEFAULT NULL,
`Incident_state` varchar(12) DEFAULT NULL,
`On_hold_reason` varchar(255) DEFAULT NULL,
`Assignment_group` varchar(45) DEFAULT NULL,
`Support_vendor_name` varchar(5) DEFAULT NULL,
`ID_vendor_ticket` varchar(25) DEFAULT NULL,
`Escalation_date` datetime DEFAULT NULL,
`Parent_Incident` varchar(12) DEFAULT NULL,
`Problem` varchar(255) DEFAULT NULL,
`Resolved` datetime DEFAULT NULL,
`Resolved_by` varchar(45) DEFAULT NULL,
`Closed` datetime DEFAULT NULL,
`Closure_CI` varchar(45) DEFAULT NULL,
`CI_Closure_Code` varchar(5) DEFAULT NULL,
`Sub_CI` varchar(12) DEFAULT NULL,
`Sub_Closure_CI` varchar(255) DEFAULT NULL,
`Resolve_time` int(11) NOT NULL,
`Duration` int(11) NOT NULL,
`Opened_weekeday` int(11) NOT NULL,
`Resolved_weekeday` int(11) NOT NULL,
`Closed_weekday` int(11) NOT NULL,
`Opened_hour` int(11) NOT NULL,
`Aging` int(11) NOT NULL,
`Gruppo_creatore` varchar(12) DEFAULT NULL,
`Gruppo_risolutore` varchar(12) DEFAULT NULL,
`Check_SSG/SSG` tinyint(1) DEFAULT NULL,
`Aging_<5` tinyint(1) DEFAULT NULL,
`Aging_hh` double DEFAULT NULL,
PRIMARY KEY (`Number`),
KEY `Resolve_time_index` (`Resolve_time`),
KEY `Duration_index` (`Duration`),
KEY `Opened_weekeday_index` (`Opened_weekeday`),
KEY `Resolved_weekeday_index` (`Resolved_weekeday`),
KEY `Closed_weekday_index` (`Closed_weekday`),
KEY `Opened_hour_index` (`Opened_hour`),
KEY `Aging_index` (`Aging`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
Table B has the same structure in order not to tamper with original data and to perform some tests.
When I use the Import Wizard from Workbech, everything is correct except that when I've a EMPTY value in field Escalation_date, wizard tells me:
(Row import failed with error: ("Incorrect datetime value: '' for
column 'Escalation_date' at row 1", 1292)
I've disabled STRICT_MODE both global and session(SET ##global.sql_mode = '';), but still import fails.
I've also tried to modify the csv, putting '0000-00-00 00:00:00' in the corresponding column, but i get the same error.
So i failed to understand which is the correct way to import this csv file.
Where am i wrong?
I had this similar problem, discovering that MySQL DATETIME fields in particular don't like CSV empty values. I ended up working around it by replacing ,, with ,NULL, within the CSV file.

Createdatetime columns is populating as 0000-00-00

I have created one table and inserting values in the table from a csv file using a python code .The createdatetime and updatedatetime columns are set to default CURRENT_TIMESTAMP.But when I am populating the data updatedatetime is populating the correct value but createdatetime is populating as 0000-00-00 00:00:00.
Here is my table definition:
CREATE TABLE `fico_details` (
`adf_contact_id` varchar(100) NOT NULL,
`sf_contact_id` varchar(100) DEFAULT NULL,
`Name` varchar(100) NOT NULL,
`BirthDate` date DEFAULT NULL,
`Address1` varchar(100) DEFAULT NULL,
`City` varchar(100) DEFAULT NULL,
`State` varchar(2) DEFAULT NULL,
`Zipcode` varchar(10) DEFAULT NULL,
`SSN` varchar(10) DEFAULT NULL,
`Address2` varchar(100) DEFAULT NULL,
`City2` varchar(100) DEFAULT NULL,
`State2` varchar(2) DEFAULT NULL,
`Zipcode2` varchar(10) DEFAULT NULL,
`Customerinput` varchar(10) DEFAULT NULL,
`AddrDiscrepancyFlg` varchar(10) DEFAULT NULL,
`Permid` varchar(10) DEFAULT NULL,
`score_date` varchar(10) DEFAULT NULL,
`reason_code_1` varchar(10) DEFAULT NULL,
`reason_code_2` varchar(10) DEFAULT NULL,
`reason_code_3` varchar(10) DEFAULT NULL,
`reason_code_4` varchar(10) DEFAULT NULL,
`CreateDateTime` TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,
`UpdateDateTime` TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
KEY `SSN` (`SSN`)
) ENGINE=InnoDB AUTO_INCREMENT=876800 DEFAULT CHARSET=utf8;
please help me to solve it.
I am working on same thing these days.
First of all I use timestamp as the datatype as apart from having datetime capabilities, it has MANY usable functions as a string as well as timestamp datatype.
I got the SAME issue as yours, what I did was alter my table was created, I would click on ALTER table using any Db tool (SQLYog in my case) and then Delete the 0000-00-00 00:00:00 value and uncheck the Not NULL check box.
This issue gets resolved EVERYTIME (whenever I create same type of table/columns)after this simple one step.
Hope this helps you too, let me know if anything still bothers you....!!

MySQL create table script with keys

I'm trying to execute this script on MySQL Server (installed on a VM with Ubuntu Server 64bit)
CREATE TABLE `MAINTABLEPARTS` (
`NAME_PARTS` varchar(300) NOT NULL,
`BRAND` varchar(60) NOT NULL,
`CODE_PART` varchar(105) NOT NULL,
`CODE_PARTS_ADVANCED` varchar(150) NOT NULL,
`CODE_PARTS_USERNUMBER` varchar(150) NOT NULL,
`EAN` varchar(13) DEFAULT NULL,
`STATUSPRODUCT` varchar(300) DEFAULT NULL,
`NAME_IMAGE` varchar(300) DEFAULT NULL,
`TTC_ART_ID` int(11) NOT NULL,
`ADDITIONAL_DATA` text,
PRIMARY KEY (`TTC_ART_ID`),
KEY (`BRAND`, `CODE_PART`, `EAN`)
KEY (`BRAND`, `CODE_PARTS_USERNUMBER`)
)
The problem is that I get an error in the query when I execute it...(something about the sql version).... the script above is automatically generated so I did not write it myself. Any ideas what might could be wrong ? If you need any further information please let me know...(MySQL version 5.7.15, query executed from MySQL Front v5.4 - build 4.148)
You are missing a comma here
CREATE TABLE `MAINTABLEPARTS` (
`NAME_PARTS` varchar(300) NOT NULL,
`BRAND` varchar(60) NOT NULL,
`CODE_PART` varchar(105) NOT NULL,
`CODE_PARTS_ADVANCED` varchar(150) NOT NULL,
`CODE_PARTS_USERNUMBER` varchar(150) NOT NULL,
`EAN` varchar(13) DEFAULT NULL,
`STATUSPRODUCT` varchar(300) DEFAULT NULL,
`NAME_IMAGE` varchar(300) DEFAULT NULL,
`TTC_ART_ID` int(11) NOT NULL,
`ADDITIONAL_DATA` text,
PRIMARY KEY (`TTC_ART_ID`),
KEY (`BRAND`, `CODE_PART`, `EAN`),
---------------------------------^
KEY (`BRAND`, `CODE_PARTS_USERNUMBER`)
)

MySQL issue with altering column to add default

I have a table named Users with a column call created. Whenever a record is created I want to add the datetime.
Users Table:
CREATE TABLE `Users` (
`userId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fullName` varchar(50) DEFAULT NULL,
`firstName` varchar(25) NOT NULL DEFAULT '',
`lastName` varchar(25) NOT NULL DEFAULT '',
`address` varchar(50) NOT NULL DEFAULT '',
`city` varchar(25) DEFAULT NULL,
`state` char(2) DEFAULT NULL,
`zipCode` varchar(25) DEFAULT NULL,
`email` varchar(50) NOT NULL DEFAULT '',
`cellPhone` varchar(15) DEFAULT NULL,
`birthDate` date NOT NULL,
`creditCard` varchar(250) NOT NULL DEFAULT '',
`subscriptionStarted` date NOT NULL,
`subscriptionEnded` date NOT NULL,
`basicPlan` tinyint(1) DEFAULT NULL,
`standardPlan` tinyint(1) DEFAULT NULL,
`premiumPlan` tinyint(1) DEFAULT NULL,
`staff` tinyint(1) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`systemAdmin` tinyint(1) DEFAULT NULL,
`edited` datetime DEFAULT NULL,
`created` datetime DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1;
now i added this extra query to make my created field get the current datetime when a new record is created.
ALTER TABLE Users
ALTER COLUMN created SET DEFAULT CURRENT_TIMESTAMP
The problem is that I get the following error when running the alter table query
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'CURRENT_TIMESTAMP' at line 2
Your syntax is slightly off, I think you have to specify the column to change:
ALTER TABLE Users CHANGE created created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
See this sample SQL Fiddle for an example.

MySQL Create Table Error 1064

I am trying to create a table in MySQL but it doesn't want to play:
create table traders(
traderID INT(9) ZEROFILL NOT NULL AUTO_INCREMENT UNSIGNED,
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT NULL,
traderFirstName VARCHAR(40) NOT NULL,
traderSurname VARCHAR(40) NOT NULL,
traderContactPhone VARCHAR(14) NOT NULL,
locationPostCode CHAR(4) NOT NULL,
traderEmail VARCHAR(120) NOT NULL,
traderBio VARCHAR(255) DEFAULT NULL,
traderReviewRating DECIMAL(5,2) DEFAULT NULL,
traderLastLogin DATETIME DEFAULT NULL,
PRIMARY_KEY(traderID)
);
And I am getting error:
"ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNSIGNED,
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT ' at line 2"
Is this something simple as I am using incorrect parameters for the table settings?
When you use UNSIGNED you must put it right beside the data type, that is: INT UNSIGNED.
Your corrected CREATE statement should look like this:
create table traders(
traderID INT(9) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY,
-- ^^^^^^^^^^^^^^^ Here is the problem.
-- Also, you can define this column as a primary key +---^^^^^^^^^^^
-- directly in the column definition |
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT NULL,
traderFirstName VARCHAR(40) NOT NULL,
traderSurname VARCHAR(40) NOT NULL,
traderContactPhone VARCHAR(14) NOT NULL,
locationPostCode CHAR(4) NOT NULL,
traderEmail VARCHAR(120) NOT NULL,
traderBio VARCHAR(255) DEFAULT NULL,
traderReviewRating DECIMAL(5,2) DEFAULT NULL,
traderLastLogin DATETIME DEFAULT NULL,
);
You may ask, "Why?" that's because there are two "types" of integer:
INT signed (which can store values from -2147483648 to 2147483647)
INT UNSIGNED (which can store values from 0 to 4294967295)
Reference:
MySQL reference: Data types > Numeric types > Integer types
Auto increment is an integer by default, no need to define unsigned.
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
try this
create table traders
(
traderID INT(9) ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY,
traderProfileName VARCHAR(64) NOT NULL,
traderPassword CHAR(128) NOT NULL,
traderFirstName VARCHAR(40) NOT NULL,
traderSurname VARCHAR(40) NOT NULL,
traderContactPhone VARCHAR(14) NOT NULL,
locationPostCode CHAR(4) NOT NULL,
traderEmail VARCHAR(120) NOT NULL,
traderBio VARCHAR(255) DEFAULT NULL,
traderReviewRating DECIMAL(5,2) DEFAULT NULL,
traderLastLogin DATETIME DEFAULT NULL
);
no need for unsigned
use primary key in same line as trader(id)
here working demo
You have some MySQL syntax errors. Here's the fix:
CREATE TABLE IF NOT EXISTS `traders` (
`traderID` INT(9) NOT NULL AUTO_INCREMENT,
`traderProfileName` VARCHAR(64) NOT NULL,
`traderPassword` CHAR(128) NOT NULL,
`traderFirstName` VARCHAR(40) NOT NULL,
`traderSurname` VARCHAR(40) NOT NULL,
`traderContactPhone` VARCHAR(14) NOT NULL,
`locationPostCode` CHAR(4) NOT NULL,
`traderEmail` VARCHAR(120) NOT NULL,
`traderBio` VARCHAR(255) DEFAULT NULL,
`traderReviewRating` DECIMAL(5,2) DEFAULT NULL,
`traderLastLogin` DATETIME DEFAULT NULL,
PRIMARY KEY (`traderID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;
I would add the preferred engine, charset, collation and auto increment start number.
If you'd like to do so just substitute the last line with:
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;
And modify as desired.
Otherwise leave the closing parenthesis.
);