3

I have a 'blog_articles' class which contains a text column named 'content'. Here is the migration :

create_table :blog_articles do |t|
  t.references :blog_user
  t.string :title
  t.text :summary
  t.text :content

  t.boolean :published, :default => false
  t.timestamps
end

I also have a custom rake task rake db:rebuild, which executes drop, create, migrate then seed. Here is the rake task :

namespace :db do
  desc "run db:drop, db:create, db:migrate and db:seed tasks in a row."
  task :rebuild => :environment do
    if Rails.env == "production"
      # Do nothing
    else
      Rake::Task["db:drop"].invoke
      Rake::Task["db:create"].invoke
      Rake::Task["db:migrate"].invoke
      Rake::Task["db:seed"].invoke
    end
  end
end

--

So my problem is, when I try to insert an article (in the seeds.rb file), with a content of more than 7768 caracters, I get a Mysql2::Error: MySQL server has gone away : INSERT INTO 'blog_articles' [...] error, using the rake db:rebuild task.

There is no problem at all if I run the rake db:seed manualy, or if I create the article in a controller.

How can I fix this ? I use a lot of my new db:rebuildtask.


edit :

So, I solve my problem by changing my rebuild task to this

namespace :db do
  desc "run db:drop, db:create, db:migrate and db:seed tasks in a row."
  task :rebuild => :environment do
    if Rails.env == "production"
      # Do nothing
    else      
      system "rake db:drop"
      system "rake db:create"
      system "rake db:migrate"
      system "rake db:seed"
    end
  end
end

I don't understand what difference it makes but this works. Does anyone have an explication ?

1

1 Answer 1

1

Try modifying your my.cnf, increasing max_allowed_packet

[mysqld]
max_allowed_packet=512M

http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html

When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues an ER_NET_PACKET_TOO_LARGE error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.

1
  • I just tried that and it doesn't work. I don't think it's a mysql conf problem since the same code work when I execute it in a controller, or if I send rake db:seed alone. Mar 17, 2013 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.