0

I am new to both RoR and SQLite; So pardon my lack of knowledge.

I ran a scaffold command:

rails generate scaffold User password:string email:string

everything worked fine, next i ran the rake db:migrate command, the terminal suggested that everything was created.

Now i opened a new terminal and i wanted to verify that the table was created, so i hit sqlite3 on terminal and ran .tables command, it shows null value.

So this time I ran sqlite3 db/development.sqlite3 command and hit .tables it said unable to open database file

next I tried sqlite3 development.sqlite3 and hit .tables command and no results were shown.

I do not understand what I am doing wrong? and I am unable to find a decent tutorial which walks one through this. please help.

here is my .yml file:

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3


test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3"
6
  • rails console and than User.all and check if the users were created Commented Jun 19, 2015 at 18:30
  • Just literally replayed that. rails new whatevs && cd whatevs; rails g scaffold User password:string email:string; rake db:migrate; sqlite3 db/development.sqlite3; .tables: outputs schema_migrations users. All fine. Commented Jun 19, 2015 at 18:32
  • I want to check from SQLITE console... Commented Jun 19, 2015 at 18:34
  • A Rails way to enter database console is rails db by the way. Commented Jun 19, 2015 at 18:34
  • D-side when i run that I get "Error: unable to open database "db/development.sqlite3": unable to open database file" Commented Jun 19, 2015 at 18:36

1 Answer 1

1

When done from-scratch, this sequence of actions produces expected results:

SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
schema_migrations  users

So problems are specific to your database. Most likely, the file was corrupted. There are many reasons why that could happen, and the easiest workaround (if data in that file is not important) is just to wipe the database file and recreate it:

rm db/development.sqlite3
rake db:create db:migrate
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.