Reputation: 31
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:rebuild
task.
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 ?
Upvotes: 3
Views: 1849
Reputation: 35370
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.
Upvotes: 1