Skip to content
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

Upgrade from 5.x to 6.x - cannot create new records because of 'alt' field #360

Open
selfsimilar opened this issue Sep 4, 2024 · 2 comments

Comments

@selfsimilar
Copy link
Contributor

selfsimilar commented Sep 4, 2024

I'm seeing the following type of MySQL error when creating new records:

Integrity constraint violation:
4025 CONSTRAINT `media.alt` failed for `db`.`media`
(Connection: mysql, SQL: 
insert into `media` (`alt`, `disk`, `directory`, `filename`, `extension`, `mime_type`, `aggregate_type`, `size`, `updated_at`, `created_at`)
 values (, public, dir, hi, m4a, audio/x-m4a, other, 29698, 2024-09-04 14:50:44, 2024-09-04 14:50:44))
{
"userId":1,
"exception":"[object]
(Illuminate\\Database\\QueryException(code: 23000): 
SQLSTATE[23000]: Integrity constraint violation: 
4025 CONSTRAINT `media.alt` failed for `db`.`media` 
(Connection: mysql, SQL: 
insert into `media` (`alt`, `disk`, `directory`, `filename`, `extension`, `mime_type`, `aggregate_type`, `size`, `updated_at`, `created_at`)
 values (, public, L2-, hi, m4a, audio/x-m4a, other, 29698, 2024-09-04 14:50:44, 2024-09-04 14:50:44)) 
at /var/task/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825)

I already had an alt column I added years ago, so I think the recent migration was just ignored. The alt column is of type text and default is NULL (so yes, it's nullable). But any attempt to add a new record appears to fail because of a media.alt constraint at the DB level. I manually changed the alt column data type from LONGTEXT to TEXT which resolved the issue. I then manually set it back from TEXT to LONGTEXT and inserts still work.

I'm happy to provide any other information and also if no one else is affected, this might just be an issue with people who manually added the alt column previously, which is probably very small minority of users.

But also, I don't know if this worth examining, but I think that every insert is putting in an empty string value for the alt column, instead of null if there's no value set.

@selfsimilar
Copy link
Contributor Author

Upon closer inspection, I initially created the alt field as a JSON column because I support translation of alt text using Spatie's Laravel-Translatable trait. This is why it breaks when trying to add a record with a blank string for the alt column when it should be NULL.

I still think that if the model's alt value is unset that inserting a blank string '' is not the correct behavior. If you agree I will see if I can help craft a PR to fix that.

@selfsimilar
Copy link
Contributor Author

My tests run clean if the alt attribute is null instead of an empty string. I've submitted a PR - #361

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

1 participant