An update like this running from SQL client such as SQLPlus works fine:
alter table `questions` add constraint `questions_question_display_format_id_foreign` foreign key (`question_display_format_id`) references `question_display_formats` (`id`);
However while the migration is running from Laravel during deployment, the following error has been observed:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0
000-00-00 00:00:00' for column 'updated_at' at row 6446 (SQL: alter table `
questions` add constraint `questions_question_display_format_id_foreign` fo
reign key (`question_display_format_id`) references `question_display_forma
ts` (`id`))
I would like to understand the cause, and how to avoid such as surprise when doing a deployment.
This example works after mass updating entries to not have created_at and updated_at columns with zeroes in them - then it worked.