0

I'm new to using Laravel. I'm working on a friend's project that uses https://packagist.org/packages/altek/accountants

We released the project into production, but we notice database errors like this:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'user_agent' at row 1 (SQL: insert into `ledgers` (`user_id`, `user_type`, `context`, `event`, `recordable_id`, `recordable_type`, `properties`, `modified`, `extra`, `url`, `ip_address`, `user_agent`, `created_at`, `updated_at`, `pivot`, `signature`) values (?, ?, 4, created, 28, App\User, {"email":"johnceo@johnceo.com","password":"blah","accept_terms":true,"updated_at":"2020-11-02 14:35:38","created_at":"2020-11-02 14:35:38","id":28}, ["email","password","accept_terms","updated_at","created_at","id"], [], https://example.com/auth/register, 172.1.1.1, Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 LightSpeed [FBAN/MessengerLiteForiOS;FBAV/288.0.0.39.118;FBBV/252761750;FBDV/iPhone12,3;FBMD/iPhone;FBSN/iOS;FBSV/13.6;FBSS/3;FBCR/;FBID/phone;FBLC/en;FBOP/0], 2020-11-02 14:35:38, 2020-11-02 14:35:38, [], 10dijfjajj3iasdio335ef37438126ed3b6ab307c996670b24ab28d6a6004f8dd00198208c46899439378321629941dae14edda681ce8235ef349343e940f4a32746aab6e00d1fe9a))

This question here says we should prepare for insanely long user agents: How big can a user agent string get?

Is there a idiomatic way to address this issue in laravel?

John
  • 32,403
  • 80
  • 251
  • 422

1 Answers1

0

You can find the answer in the package documentation here

While odd, on some occasions, User Agent values may go over the 255 character mark. To avoid insertion problems, update the column from $table->string('user_agent')->nullable(); to $table->text('user_agent')->nullable();

Jhonatan Bianchi
  • 120
  • 2
  • 12