Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
technowhizz opened this issue Aug 2, 2023 · 4 comments
Open

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

technowhizz opened this issue Aug 2, 2023 · 4 comments

Comments

@technowhizz
Copy link

technowhizz commented Aug 2, 2023

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
Copy link
Author

technowhizz commented Aug 3, 2023

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
Copy link

nitz commented Oct 6, 2023

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
Copy link
Author

@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
Copy link

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

Thanks for the contributions and this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants