I am using Slick 3.1.1 with MySql 5.6.33.
I executed schema code generation to generate the code for representing the 'invoices' table in our production server. Here is a segment of the generated code.
class Invoices(_tableTag: Tag) extends Table[InvoicesRow](_tableTag, "invoices") {
...
/** Database column created_at SqlType(DATETIME) */
val createdAt: Rep[java.sql.Timestamp] = column[java.sql.Timestamp]("created_at")
/** Database column updated_at SqlType(DATETIME) */
val updatedAt: Rep[java.sql.Timestamp] = column[java.sql.Timestamp]("updated_at")
...}
I then create the table locally, using the generated code (as explained here), and found that the created table contains the following 2 columns:
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
However, the same columns of the 'invoices' table in the production server, are defined without the default value or the ON UPDATE trigger:
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
These discrepancies causes my tests to fail because every time I update a row, the field 'created_at' is updated too with the current timestamp (while I need the field to keep it's existing value).
Why do these discrepancies exist? Why does Slick add the 'ON UPDATE CURRENT_TIMESTAMP' segment? Is there a way to stop Slick from adding the 'ON UPDATE CURRENT_TIMESTAMP', or at-least a way to remove the 'ON UPDATE' definition from the table (after it's creation)?