Antelope-Valley-College / polr

GNU General Public License v2.0
24 stars 10 forks source link

Migration Error: Invalid default value for 'created_at' #9

Open technowhizz opened 1 year ago

technowhizz commented 1 year ago

When running php artisan migrate I experience the issue below. I've tried changing the sql mode to no avail.

Im running Mysql 8.0.33-0 Ubuntu 22.04 Laravel: 9.52.13

 Illuminate\Database\QueryException 

  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: ALTER TABLE links CHANGE secret_key secret_key VARCHAR(255) CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_unicode_ci`, CHANGE created_at created_at TIMESTAMP DEFAULT '0000-00-00 00:00:00' NOT NULL, CHANGE updated_at updated_at TIMESTAMP DEFAULT '0000-00-00 00:00:00' NOT NULL)

This is being caused by database/migrations/2023_01_24_234401_add_secrets_key_default.php:21

If I can get it working I'll make a PR with the fix but in the meantime has anyone else come across this?

technowhizz commented 1 year ago

Looking further into this I found that the useCurrent() function was returning 0000-00-00 00:00:00 instead of CURRENT_TIMESTAMP. The same with useCurrentOnUpdate(). I've made #11 as a workaround incase someone hits the same issue. Not sure why this is happening

nitz commented 1 year ago

Your change in 2b8d2c6c0a04ceede02302a0bd8d8f10a0394a9b resolved this issue for me too. I was moving over to this fork from the official one due to being forced to update to PHP 8+, and ran into the same error you ran into after applying the changes found in #6. Changing that migration as your PR does let me migrate successfully and get my instance running again. I greatly appreciate it!

technowhizz commented 1 year ago

@nitz Yeah I was in the same situation a while ago. Thought it would be good to push the fixes back up. Glad it helped :)

My PR overall contains a bunch of fixes and nice to haves too!

Hopefully @mwilmes-at-avc will have time to review and approve soon :)

droplinxuser commented 2 weeks ago

I encounter the same issue on PHP 8.3, and applying the patch here works great.

Thanks for the contributions and this repo.