small medium large xlarge

05 May 2009, 03:10
John Sinton (1 post)


Attempting to put sessions into the database (Chapter 8 Task C), I run into a “Data too long for column” problem if I use MySQL, but the identical setup works fine for SQLLite3. I’m only changing the database.yml file, with everything identical as far as I can tell, dropping all tables manually and doing a migrate from an empty database. Both databases appear to use a varchar with a limit of 255 for session_id when I look at the table definitions. All examples worked fine with MySQL to this point.

I can of course use SQLLite3 to go through the book, but I’m really trying to understand Rails better, so I’d like to be able to understand a situation like this and how I would go about understanding it and correcting it.

Any ideas what this problem is, and even more importantly, how I would go about understanding what is maybe just a configuration problem without attempting to learn all of Rails?

It looks like it could be something to do with a newer version of Rails - I have 2.3.2 and Ruby 1.8.6, and some of the changes listed in the Prag Prog updates for 2.3 don’t seem to apply (for example, there did not seem to be any line to uncomment as suggested ‘Page 99/107: the line to uncomment in environment.rb now looks as follows: ActionController::Base.session_store = :active_record_store’). Maybe it’s just that I need to be more careful in upgrading to later versions of Rails not assuming forward compatibility, and sticking to one (older) version that is compatible?

Thanks for any suggestions or pointers!

Status: 500 Internal Server Error Mysql::Error: Data too long for column ‘session_id’ at row 1: INSERT INTO sessions (updated_at, session_id, data, created_at) VALUES(‘2009-05-05 02:33:42’, ‘BAh7CDoQX2NzcmZfdG9rZW4iMURpUkN2RFFWM0s0c1JRZ1k3NHg2MUlsdHlSUnlXNisyb2MxbUd1dTBsdFU9Og9zZXNzaW9uX2lkIiUwNmY3ZGJjMjVjMjQzMmNhYjM3NDQ1MDdhZWY5N2IzZCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==–cc1413bb935b8848a4cff4c3af3c7f9e28be7116’, ‘BAh7BzoQX2NzcmZfdG9rZW4iMWxxczdCMXFQL1ArdE9uWk1qU3FWMnJiY0Z0\nNy8zT2gybXFvN2VRdkRvdW89IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy\nOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA\n’, ‘2009-05-05 02:33:42’)

07 May 2009, 13:55
Kedar Mhaswade (21 posts)

I agree with your sentiment. For a newbie, this does get challenging. However, I am a newbie as well, but haven’t run into this problem. I have Rails 2.3.2 and Ruby 1.8.6 on Ubuntu Intrepid and things work fine. Also, regarding the environment.rb, the foot-note on page 99 does say that the this setting has moved to session-store initializer.

I think it makes sense to try hard to make it work with the latest stable releases available and understand the compatibility differences. (A comment on rails I have here is that maybe in environment.rb, they can put a little note saying #with rails x.y.z, put the session-store information in initializers/session-store.rb).

Maybe rake db:sessions:clear followed by db:sessions:create helps?


23 Jun 2009, 17:54
Karl-Heinz Wild (1 post)

I’ve had the smae problem with pgsql. In an other thread was described to delete the session cookie in the browser. For me, it worked!

04 Jul 2009, 15:43
Jean-Denis VAUGUET (4 posts)

I edited to reflect this.

05 Jul 2009, 23:38
Andrew Kay (3 posts)

I had the same issue with mysql. I just chopped my secret key to 30 chars and that solved the problem. Not sure how long that key can be before it hits the 255 var char limit (the key originally wasn’t 255 chars…) in mysql though.

13 Jul 2009, 03:49
Jeffrey A Grunschel (1 post)

I too am having errors while using MySQL. The server log says:

Mysql::Error: Data too long for column 'session_id' at row 1: 
INSERT INTO `sessions` (`updated_at`, `session_id`, `data`, `created_at`) 
VALUES('2009-07-12 22:58:36', 
'2009-07-12 22:58:36')

AT: Karl-Heinz Wild

Do you know where that other thread is?

AT: Andrew Kay

Changing the length of :secret in session_store.rb did not work for me. It would seem that the algorithm that is used to hash the information for session is generating too long of a hash. Since, I’m just learning, I’ll post my secret. It definitely does not match anything in the above server error…something beyond my understanding is happening.

  :secret      => 'f4b3a7f2ad5ea95fb48f8d50ad4be7'


As it turns out, when I was trying to clear my browser cookies, I actually wasn’t. Karl-Heinz Wild, nailed it on the head. Deleting the browser cookies did the trick.

24 Jul 2009, 02:28
drew kee (1 post)

Yes indeed, deleting the browser cookies solved the issue for me too.

You must be logged in to comment