# How to import db

**URL:** <https://www.ruby-forum.com/t/how-to-import-db/168421>\
**Category:** Rails\
**Created:** [May 20, 2009, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-import-db/168421 "2009-05-20T17:40:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 20, 2009, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-import-db/168421/1 "2009-05-20T17:40:57Z")

</div>

I’m just starting out learning. So far, all I’ve done is little test  
apps starting from scratch – ie, ones in which rails creates an empty  
database, then I make up some classes and views and controllers and  
such. Nice system. But what if I have an SQlite database file created  
elsewhere: (how) can I import this into ruby “easily”? I have not  
tried yet because it just occurred to me that there is an id  
field/column in the “native” rails databases. Could I add such a column  
and then just copy the db file straight into db/development.sqlite?

I am guessing the easiest way might be to just create an empty db with  
all the necessary tables and columns and then write a script to copy the  
relevant data in from the existing external db.

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 21, 2009, 8:39pm UTC](https://www.ruby-forum.com/t/how-to-import-db/168421/2 "2009-05-21T20:39:25Z")

</div>

Hi…  
I have a similar system where my source db is legacy Oracle db. What I  
have done is use MySQL db for development and Oracle in other  
environments…You will need the schema for setting up local. Don’t  
import the db at one go… Create migrations as you establish models and  
associations for the app…  
you can use SQL scripts if you want soem raw test data.

Thanks

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 21, 2009, 9:00pm UTC](https://www.ruby-forum.com/t/how-to-import-db/168421/3 "2009-05-21T21:00:16Z")

</div>

Manasi V1 wrote:

> Hi…  
> I have a similar system where my source db is legacy Oracle db. What I  
> have done is use MySQL db for development and Oracle in other  
> environments…You will need the schema for setting up local. Don’t  
> import the db at one go… Create migrations as you establish models and  
> associations for the app…  
> you can use SQL scripts if you want soem raw test data.
> 
> Thanks

Actually this was just for learning purposes. I don’t really want to  
sit and manually add entries in a browser – I’d like a decent size  
database to play with while I get used to API. So I’m writing a short  
ruby script to collate some filesystem data into an sqlite3 file. Which  
shouldn’t take much longer, hopefully everything will be okay. If not I  
will just pull the rails “development.sqlite3” file out and add to that  
(I guess that’s really what I should be doing…). I’m using the same  
fields as in the schema, plus “id”, which AFAICT is just an int count  
(1,2,3…).

So I was wondering if there are any caveats about this. (It’s a  
pre-emptive post; the next one will be “Whhaaa…Why won’t the database  
I made work in rails?”) 😉

MK
