SQlite3 commands aren't displaying tables from rails tutorial application
This is probably something simple I'm missing. I'm working through the pragmatic bookshelf ruby on rails exercises in the AWDWR 4th edition.
Everything was going well and then I ran into the portion where you enter into the sqlite 3 command line tools to make sure it's capturing the order information.
When I try to run the select statement for orders, I get:
sqlite> select * from orders;
SQL error: no such table: orders
Then I tried listing all the tables:
sqli开发者_如何学Pythonte> .tables
sqlite>
I get to the sqlite command line per the instructions in the book:
sqlite3 -line
Is there something simple I'm missing here?
Thanks.
You need to specify a database filename on your sqlite3 command line. Usually*, if you do not give a database filename, then it will start out operating on an empty, temporary, in-memory database.
*
The version I have at hand (sqlite3 3.7.2) actually takes -line
as the database filename if there are no additional arguments. This means that I end up with a file named -line
; this file can be deleted with rm ./-line
.
You probably want this (run from the root directory of your application):
sqlite3 -line db/development.sqlite3
If your project is using Rails 3, then you can use this:
rails db
If you need the -line
behavior, you can use .mode line
at the sqlite3 command line.
If you want to access the DB for a non-default environment, just append the environment name:
rails db staging
You can also add in -p
if you want to automatically use the username and password from your configuration (sqlite3 does not need a username or password since it uses plain Unix permissions):
rails db -p production
To display all the tables in the sqlite:
>select * from sqlite_master
I had a similar problem (not getting anything back), but I'm using Windows, and it seems to have a problem when I use the drives with the path (c:\ or d:). I was able to solve it by and launching sqllite from the db path, and using only the file name, like this:
C:\mydir\sqlite3.exe -line mydb.db
.tables
or
C:\mydir\sqlite3.exe
.open mydb.db
or
C:\mydir\sqlite3.exe
ATTACH "mydb.db" AS db1;
To display a table:
select * from mytable;
or
select * from db1.mytable;
Go into the db folder by terminal and type
$ sqlite3 development.sqlite3
SQLite version 3.7.7 2011-06-25 16:35:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .table
and it will show the tables you have made.
精彩评论