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 7619567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:43:10+00:00 2026-05-31T03:43:10+00:00

Hi I have a sqlite3 database full of data from my previous version of

  • 0

Hi I have a sqlite3 database full of data from my previous version of the web app which WASN’T written in rails. Im now rewriting the web app in rails from scratch. But Id like to use the data from my previous app in the new rails app. Whats the best way to accomplish this?

This is what Ive tried so far and it didn’t work very well:
1) I created a new rails app

2) replaced my sqlite3 database in the new app with the sqlite3 database from the old app

3) Created a model with the same schema as the old DB.

4) changed the databse.yml file with the updated DB file details

5) un my model added the “establish_connection” method

6) I could thus get it to show me all the details of the old database in my browser @”index.html”

7) However, I ran into problems when wanting to insert/edit records into the DB. Since the DB did not have a primary key column for each row, it didnt work.

8) So I tried to do a migration to add a column with a primary key . It didnt work

9) suddenly a new development.sqlite3 database had shown up in the app and it was trying to add a primary key to the NEW DB.

10) So I just deleted the new DB that had popped up and after that the app wasn’t working

11) Now I want to start from scratch and so my question:
“Whats the best way to import data from a previous non-rails app (in a sqlite3 DB format) into a new rails app”

  • 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-05-31T03:43:12+00:00Added an answer on May 31, 2026 at 3:43 am

    You want to be working with 2 databases, the old and the new. So, your database.yml needs to have 2 connections in it. One should be your normal connection called development or production and the other should be called legacy. Fill out their different connection information. By default, your ActiveRecord models will pull from the one not called legacy.

    Create a model called LegacyBase. In the model put establish_connection "legacy". Now create a directory at app/models/legacy. Put all of the models represent data from the old DB inside this directory. All of those models should extend from LegacyBase. This will mean they’re all reading from the old DB.

    Create your new models. Do you want them to have a primary key column? If not, see this answer. Create an ActiveRecord database table with no :id column?. They will by default have an id column, though and I recommend leaving it that way.

    For each of the legacy models, write a method called to_model. In this method, write the code that creates a new object and populate it with the old data and save it. Something like this:

    class OldUser < LegacyBase
    
        establish_connection "legacy"
    
        def to_model
            User.create!(self.attributes)
        end
    end
    

    You can do any logic that needs to happen to make the old data fit your new app. Call this method on all of the old records like OldUser.all.map(&:to_model).

    Do this for all of the tables that you want to move over.

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

Sidebar

Related Questions

I have SQLite3 database, which is populated with some large set of data. I
I have a query for sqlite3 database which provides the sorted data. The data
I have succeeded in generating a sqlite3 database in my android app from an
I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting
I have a grid of UIImageViews. The images names come from a sqlite3 database.
I have a Python application. It has an SQLite database, full of data about
I have an SQLite3 database which, in order to optimize performance, uses computed columns
My iPhone app uses a sqlite3 database for storing the data that it generates.
I have an sqlite database full of huge number of URLs and it's taking
I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation

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.