Hello.
When i trying to fire:
event(new PostViewed($post));
Sometimes (usually at mobile devices) I got error like this.
SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'agent' at row 1 (SQL: insert into canvas_views (post_id, ip, agent, referer, updated_at, created_at) values (bd50dcc6-c38d-4155-8da2-95d8f3644887, 95.50.47.229, Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 [FBAN/FBIOS;FBDV/iPhone11,2;FBMD/iPhone;FBSN/iOS;FBSV/13.6;FBSS/3;FBID/phone;FBLC/pl_PL;FBOP/5], http://m.facebook.com, 2020-08-25 12:33:46, 2020-08-25 12:33:46))
'Agent', 'referer' fields are to short.
So the agent string I grabbed off of your comment above looks to be 205 characters. Since the default string length on a migrated column is 255, could you verify the column type for agent or referer you see in your database?
Hi @austintoddj,
I can confirm this is an issue. I have my database charset set as utf8mb4, so I run with Schema::defaultStringLength(191); in my AppServiceProvider's boot method. This prevents filling string fields with more than 191 characters. I see now that this is only if you have an "older" MySQL version:
Laravel uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them.
_From Laravel Migration docs, Index Lengths & MySQL / MariaDB_
I personally solved this issue by making the agent columns in canvas_views and canvas_visits text instead of varchar. I'm on MySQL 8 now so I can probably remove the defaultStringLength setting, but my app was created before MySQL 5.7.7 was released.
@hoRacy Can you confirm if you also use the Schema::defaultStringLength in your app? What MySQL version are you using? (Or MariaDB if that is what you use...) Does removing the defaultStringLength fix the issue for you?
Facing the same issue when opening the post links from instagram, probably due to the web view from mobiles, when you select open in chrome the issue is not seen.
@NavaneethVijay @hoRacy Getting a fix in now. Should be up in a few minutes.
Fixed in 5.4.1