Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:53:44+00:00 2026-06-09T22:53:44+00:00

I’m trying to seed about 2K records into a model and I’ve tried using

  • 0

I’m trying to seed about 2K records into a model and I’ve tried using all the different methods out there so far (faster csv, fast_seeder, and the railscasts ep). I feel like this should be pretty simple. I’ve got all the data in a CSV file and I’ve got the model set up already, ready to be seeded.

The only thing that’s worked so far is what’s shown in the RailsCasts episode. I plugged in this code for my attributes, and it seeded only the first line (out of 2K), and that’s it:

Country.delete_all
open("#{Rails.root}/path_to_my_file") do |models|
  models.read.each_line do |model|
     column_1, column_2, column_3, column_4 = model.chomp.split(",")
     Model.create!(:attr_1 => column_1, :attr_2 => column_2, ...etc)
  end
end

Then I tried using FasterCSV based on some of the other questions, but I received a bunch of errors saying that fastercsv was already included in the latest release of ruby, I couldn’t seem to figure it out (this could be my fault, but I haven’t been able to find a good SO question that lays it out nicely).

Finally, Fast_Seeder seemed to have some potential, and it recognized all my entries, but didn’t save any of them into the model because I received this error:

SQLite3::SQLException: too many terms in compound SELECT:(all my columns)

Anyway, again I feel like this should be simple enough. I just have a CSV with 2K entries, and a blank model that I need to seed. Best way to do this would be much appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:53:45+00:00Added an answer on June 9, 2026 at 10:53 pm

    Best success I’ve seen with this is by doing a rake task.

    require 'csv'
    
    namespace :csv do
    
      desc "Import CSV Data"
      task :import_stuff => :environment do
    
        csv_file_path = 'db/data.csv'
    
        CSV.foreach(csv_file_path) do |row|
          Model.create!({
            :column1 => row[0],
            :column2 => row[1],
            :column3 => row[2],        
          })
          puts "Row added!"
        end
      end
    end
    

    Put this in your lib/tasks folder with a .rake extension and to run it type: “rake csv:import_stuff”

    Also, you might be reaching some limitations with SQL lite… I would suggest checking out MongoDB. It seems like it would be fitting for your current situation. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.