0

I am learning RoR using M Hartls Rails tutorial book. I am very much new to the world of databases. I created the application(simple one, just on 3rd chapter) and did my RSpec and made few static pages. I wanted to migrate from sqllite3 to postgres. I changed the database.yml to postgres deleting the full sqlite3 specifications. Now I run my app it does not work? It says 'PG:' Error.

I need to first understand how the data is stored in sqlite? I searched the db directory and I could not find the development.rb or any database file (probably because I altered the database.yml file)

In this case, I did not enter any data as such,(it still does not work , gives me error) but generally, where does the data get stored? and since I changed the database.yml file to postgres, what will happen to the existing data?

what does rake db:migrate command do?

It would be great if someone gives a simple analogy or explanation is to how this is stored then finding a solution for this problem becomes much easier.

1
  • Once the idea of how data is stored is clear, it will become more clear is to how taps work and how to generally migrate between databases. Commented Jun 10, 2014 at 9:58

1 Answer 1

0

sqlite stores its data in files in a folder on your filesystem, using its own system of storage.

postgres will do a similar thing, but in a different folder, using a different system.

You will generally never touch these folders. You don't need to know where they are or how the dbms (database management system, eg sqlite or postgres) stores the data. All your interaction with your dbms will be done either via the terminal, or the dmbs's shell client (which you launch in the terminal aka the shell), or via a desktop client, or via your rails app's own connection with the dbms.

When you make a new rails project you need to create the database it will use. If you switch to using a different dbms then you will need to create a new database in that dbms for your app to use. Google how to do this.

If you have data in one dbms and you want to bring it into a different dbms then you will need to export it from the first dbms and import it into the second dbms. Google how to do this.

rake db:migrate will run any migrations which haven't been run in your current database (ie the one in your database.yml). Rails creates a table in your database to store which migrations have been run already: this is how it keeps track. It will fail if you haven't created the database yet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.