AWS SCT - MySQL DDL differences - mysql

Im trying to use AWS SCT to copy the schema of one aws rds mysql database to another aws rds mysql database (same engine). When applying the schema changes via the AWS SCT tool, i get a few errors mostly similiar
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 'DEFAULT_GENERATED, updated_at timestamp DEFAULT
(CURRENT_TIMESTAMP) DEFAULT_GEN' at line 9
I then compare the schema definition that aws sct is showing with what i can see in mysql workbench and it seems to have replaced CURRENT_TIMESTAMP with DEFAULT_GENERATED does anyone know why? The preassessment check mentioned 100% could be copied/converted
aws sct showing the table
CREATE TABLE test.authentication (
id varchar(36) NOT NULL,
...
created_at timestamp DEFAULT (CURRENT_TIMESTAMP) DEFAULT_GENERATED,
updated_at timestamp DEFAULT (CURRENT_TIMESTAMP) DEFAULT_GENERATED on update CURRENT_TIMESTAMP,
deleted_at timestamp DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT email_dtype_unique UNIQUE (email, dtype)
);
mysql workbench
CREATE TABLE `authentication` (
`id` varchar(36) NOT NULL,
...
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL,
`verified` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

Related

Stuck on a SQL Syntax error

I'm a little bit stuck with my SQL models. I use MySQL Workbench to create models graphically and i greated a schema which i think fits my use case. However i can't synchronnise with the database because it gives me the following error. Maybe someone else can see what i did wrong. Apparantly i'm blind currently...
Executing SQL script in server ERROR: Error 1064: You have an error in
your SQL syntax; check the manual that corresponds to your MariaDB
server version for the right syntax to use near 'NULL DEFAULT
CURRENT_TIMESTAMP,
last_activity DATETIME NULL DEFAULT NULL,
' at line 6
SQL Code:
CREATE TABLE IF NOT EXISTS `topas`.`user` (
`id` INT(255) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(50) NOT NULL,
`email` VARCHAR(80) NULL DEFAULT NULL,
`password` VARCHAR(250) NOT NULL,
`created_at` NULL DEFAULT CURRENT_TIMESTAMP,
`last_activity` DATETIME NULL DEFAULT NULL,
UNIQUE INDEX `username_UNIQUE` (`username` ASC),
UNIQUE INDEX `email_UNIQUE` (`email` ASC),
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
SQL script execution finished: statements: 3 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Thanks.
This line:
`created_at` NULL DEFAULT CURRENT_TIMESTAMP,
is missing type definition. It should be:
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
This line is missing a data type
`created_at` NULL DEFAULT CURRENT_TIMESTAMP,
You will need to set it to either TIMESTAMP or DATETIME:
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
you are missing the column type for created_at column.
should be:
`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,

Create table with default values giving error

Using MySql Workbench 6.3 Build version 6.3.6.
I am trying to create a table with Default constraint but its giving me error.
Here is the script
Create Table `Migration_Log2` (
`Id` Int NOT NULL AUTO_INCREMENT,
`FilePath` varchar(1000) NOT NULL,
`FileName` varchar(100) NOT NULL,
`IsSent` bool NOT NULL DEFAULT '0',
`CreatedDate` DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`ModifiedDate` DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`SendAttemptMade` int NOT NULL DEFAULT '0',
`Message` Text DEFAULT NULL,
PRIMARY KEY (`Id`),
KEY `migration_log_Id_UNIQUE` (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Error Message
Error Code: 1067. Invalid default value for 'CreatedDate' 0.000 sec
This may be due to some strict constraint on the data type check on database server.
I would suggest to change type of field CreatedDate from datetime to timestamp.
I had faced similar issue in a VPS for my website.
Your CURRENT_TIMESTAMP might have been appending the microseconds in the output.
Try to use: CURRENT_TIMESTAMP(0) as the default value.
SELECT CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(0), CURRENT_TIMESTAMP(1), CURRENT_TIMESTAMP(2);
The microseconds mattered, possibly. See the differences.

Difference of datetime type in mysql 5.5.46 and 5.6.28

Have table in mysql 5.5.46 and same table in 5.6.28. I backup database on mysql 5.5.46 and then restore it on 5.6.28. So table have same structure and same data on both servers.
CREATE TABLE `test` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Path` varchar(250) NOT NULL,
`Link` varchar(250) NOT NULL,
`Company` varchar(250) NOT NULL,
`Width` int(11) NOT NULL,
`Height` int(11) NOT NULL,
`View_Count` int(11) NOT NULL DEFAULT '0',
`create_date` datetime NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8
Have query like this :
insert into test(path,link,company,width,height,view_count)
values('test','test','test',10,10,10)
On mysql 5.5.46 this query execute successfully and create_date value is '0000-00-00 00:00:00'
On mysql 5.6.28 have an error Field 'Create_Date' doesn't have a default value and it's logically because create_date is not null so it does not have any default value. But how it works on 5.5.46 ?
Based on the information you gave us, it appears that you were running MySQL 5.5.46 in non strict mode, but running MySQL 5.6.28 in strict mode. From the MySQL documentation:
TIMESTAMP columns declared as NOT NULL and without an explicit DEFAULT clause are treated as having no default value. For inserted rows that specify no explicit value for such a column, the result depends on the SQL mode. If strict SQL mode is enabled, an error occurs. If strict SQL mode is not enabled, the column is assigned the implicit default of '0000-00-00 00:00:00' and a warning occurs. This is similar to how MySQL treats other temporal types such as DATETIME.
Your create_date column is of type DATETIME, and it appears that you were trying to do the INSERT in the 5.6.28 database in strict mode, and hence getting an error.

MySQL: CURRENT_TIMESTAMP for date field works locally but not on server

I have a date column whose default value is CURRENT_TIMESTAMP. It works fine locally, but when I did an export and tried to create the database on my hosting I get this:
`Invalid default value for 'created'`
...from this code:
CREATE TABLE IF NOT EXISTS `bookings` (
`id` varchar(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`cloned` int(11) DEFAULT NULL,
`event_id` varchar(11) NOT NULL,
`amount_due` smallint(6) NOT NULL,
`vat` tinyint(2) NOT NULL,
`discount` tinyint(4) DEFAULT NULL,
`date_paid` date DEFAULT NULL,
`notes` mediumtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The answer to this question says that, apparently, CURRENT_TIMESTAMP is an acceptable default only for datetime, not date, columns. But like I say, it works locally, just not remotely.
Could it be to do with the difference in MySQL versions?
Local MySQL: protocol v10 / server v5.6.16
Remote MySQL: protocol v10 / server v5.5.35
Am I getting away with this locally because of the higher server version?
This won't work for MySQL 5.5; before mysql 5.6.5 CURRENT_TIMESTAMP works only for TIMESTAMP.
http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html
It's working for you locally, because you are using MySQL 5.6.16 there.
In the MySQL manual a Timestamp datatype is recommended for use with "DEFAULT CURRENT_TIMESTAMP".
Also consider this (taken from the MySQL manual):
One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.
try using
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

Mysql DDL works on local wamp but does not import on online server

I am using this schema on localhost wamp MySQL server and it works fine:
CREATE TABLE `tblcustomers` (
`customerid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`customername` varchar(50) NOT NULL,
`customerphone` varchar(11) DEFAULT NULL,
`customeraddress` varchar(255) DEFAULT NULL,
`registrationdate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `credid` (`customerid`),
UNIQUE KEY `credname` (`customername`),
UNIQUE KEY `customerid` (`customerid`)
) ENGINE=InnoDB AUTO_INCREMENT=110 DEFAULT CHARSET=latin1;
MySQL said: Documentation
#1067 - Invalid default value for 'registrationdate'
When I import the dump file on online server I get the message above. How to deal with it?
change datatype for registrationdate FROM DATETIME to TIMESTAMP and you should be through