Skip to content

Conversation

@oriondevelops
Copy link
Contributor

The 'subject_alternative_names' column in the migration had a default value of an empty JSON array as a string, which caused an error when running the migration. This PR fixes the error by updating the default value to use an Expression as documented here.

Using an Expression instance will prevent Laravel from wrapping the value in quotes and allow you to use database
specific functions. One situation where this is particularly useful is when you need to assign default values to JSON
columns.

Fixes #29

@Daanra Daanra merged commit 0932672 into Daanra:master Mar 14, 2023
@Daanra
Copy link
Owner

Daanra commented Mar 14, 2023

Thank you!

@ericbae
Copy link

ericbae commented Mar 29, 2023

I'm still getting an error

SQLSTATE[42883]: Undefined function: 7 ERROR: function json_array() does not exist HINT: No function matches the given name and argument types. You might need to add explicit type casts. (Connection: pgsql, SQL: alter table "lets_encrypt_certificates" add column "subject_alternative_names" json not null default (JSON_ARRAY()))

I'm running on Laravel 10 and PostgreSQL 14. In fact, in Postgres, the previous default value works well. which was default('[]')

@Daanra
Copy link
Owner

Daanra commented Mar 29, 2023

@ericbae For now, you can edit the migration after publishing it.

If anyone knows how to make this work for all databases, I'd appreciate a PR.

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

Successfully merging this pull request may close these issues.

Issue with newest migration under MySQL

3 participants