Hello, using MySQL, FasterCSV and have a CSV dump of blog posts to be
imported as production data, except the created_at and updated_at
columns are always populated for me and not read from the CSV!
I tried renaming the columns, tried changing the type to import them
as strings, this worked (as strings), but then when I changed the type
to datetime, they NULL''d out (expected?).
This happens for all my models that use the timestamp columns. All
tables were created from migrations using t.timestamps.
I tried messing with record_timestamps as well to no avail. this must
be a general problem, hoping it''s something simple. tia!
def import_csv(file)
name = File.basename(file, ''.csv'')
puts
puts "truncating existing #{name} data..."
ActiveRecord::Base.connection.execute("truncate table
#{name.pluralize.underscore}")
puts "parsing #{name}.csv..."
rows = FasterCSV.read(file, :quote_char => ''\\'')
column_names = rows.shift
puts "importing #{rows.size} rows..."
count = (eval "#{name}.import(column_names, rows)").num_inserts
puts "successfully imported #{count} rows!"
puts
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---