Migration to create a new expiry column with the default date one year from now
I've seen a few threads on how to set the default of a timestamp column to the current datetime using CURRENT_TIMESTAMP. However, I am looking for how to set the default to the CURRENT_TIMESTAMP + 1 year.
SQLSTATE[42000]: Syntax error or access violation: 1064 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 '+ INTERVAL 1 YEAR after updated_at' at line 1
Any idea on how to set the default for this column to be the one year from the current date?
i would do it during the record creation and/or update using carbon
$expire_date = Carbon::now()->addyear();
where $expire_date takes the current datetime value and adds a year. i haven't tried the code but it may spit out a different format not matching the database column but you can use carbon to set the format as well.
you can also set triggers in the database but i haven't done that in a while. many ways to do it.
With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP or DATETIME column. See Section 11.3.5, “Automatic Initialization and Updating for TIMESTAMP and DATETIME”.