Ruby on rails 无法在sqlite3中迁移rake db之后查看表
我不熟悉rails。我正在使用Rails 4.0.0和ruby 2.0.0。我通过Kevin Skoglund提供的Ruby on Rails 4基本培训进行学习。他在这方面使用mysql,但我无法安装它,所以我切换到sqlite3,一切正常 问题:我正在运行rake db:migrate。它似乎运行正常,但在sqlite3中我看不到db中的表 详细信息:使用创建db simple_cms_开发Ruby on rails 无法在sqlite3中迁移rake db之后查看表,ruby-on-rails,sqlite,rake,Ruby On Rails,Sqlite,Rake,我不熟悉rails。我正在使用Rails 4.0.0和ruby 2.0.0。我通过Kevin Skoglund提供的Ruby on Rails 4基本培训进行学习。他在这方面使用mysql,但我无法安装它,所以我切换到sqlite3,一切正常 问题:我正在运行rake db:migrate。它似乎运行正常,但在sqlite3中我看不到db中的表 详细信息:使用创建db simple_cms_开发 sqlite3 simple_cms_development.db 通过在“development
sqlite3 simple_cms_development.db
通过在“development:”中将simple_cms_development的位置设置为“database:”在database.yml中配置项目。然后就跑了
rakedb:schema:dump
将rails连接到数据库并导出模式
然后,我使用modelby生成了迁移
rails生成模型用户
在create_users.db内部
class CreateUsers < ActiveRecord::Migration
def up
create_table :users do |t|
t.column "first_name", :string, :limit => 25
t.string "last_name", :limit => 50
t.string "email", :default => "", :null => false
t.string "password", :limit => 40
t.timestamps
end
end
def down
drop_table :users
end
end
我检查了schema.rb,它有:
ActiveRecord::Schema.define(version: 20140121101037) do
create_table "users", force: true do |t|
t.string "first_name", limit: 25
t.string "last_name", limit: 50
t.string "email", default: "", null: false
t.string "password", limit: 40
t.datetime "created_at"
t.datetime "updated_at"
end
end
到目前为止,一切都很顺利
然后我在sqlite3中打开simple_cms_development.db,并尝试通过
查看表。tables
没有显示任何内容,没有错误。它只显示另一个sqlite提示符。它应该显示schema_迁移和用户。我应该怎么做?从终端转到您的项目目录并粘贴以下行:
sqlite3-line db/development.sqlite3
然后您将找到数据库控制台,现在您可以在此处编写查询,如下所示:
sqlite>select*from users阅读、跑步
帮我修好了 Rails将使用
/config/database.yml
文件中指定的任何数据库,而不是从命令行创建的数据库。对于SQLite数据库,这些数据库通常存储在/db
目录下。您能检查一下database.yml文件中有什么吗?有一个类似的问题,rails测试无法再访问作为添加列迁移目标的表。
ActiveRecord::Schema.define(version: 20140121101037) do
create_table "users", force: true do |t|
t.string "first_name", limit: 25
t.string "last_name", limit: 50
t.string "email", default: "", null: false
t.string "password", limit: 40
t.datetime "created_at"
t.datetime "updated_at"
end
end
rails db:drop db:create db:migrate RAILS_ENV=test