在sqlite3中rake db:migrate之后无法看到表

问题描述 投票:1回答:2

我是铁杆新手。我使用的是Rails 4.0.0和ruby 2.0.0。我正在学习Kevin Skoglund的Ruby on Rails 4必备培训。他使用mysql,但我无法安装它,所以我切换到sqlite3,一切正常。

问题:我正在运行rake db:migrate。它似乎运行正常,但我无法在sqlite3中看到db中的表。

DETAILS:使用创建db simple_cms_development

sqlite3 simple_cms_development.db

通过在'development:'中将simple_cms_development的位置设置为'database:',在database.yml中配置项目。然后跑了

rake db:schema:dump将rails连接到数据库并导出模式。

然后我使用model by生成了迁移

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

然后我跑了迁移rake db:migrate。我有:

==  DoNothingYet: migrating ================
==  DoNothingYet: migrated (0.0000s) =======

==  CreateUsers: migrating =================
-- create_table(:users)
   -> 0.1941s
==  CreateUsers: migrated (0.1951s) ========

我检查了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_migrations和用户。我该怎么办?

ruby-on-rails sqlite rake
2个回答
2
投票

从终端转到项目目录并粘贴以下行:

sqlite3 -line db / development.sqlite3

然后你会找到数据库控制台,现在你可以在这里写下你的查询:

sqlite> select * from users;


0
投票

this post,跑步

rails db:drop db:create db:migrate RAILS_ENV=test

为我修好了。

© www.soinside.com 2019 - 2024. All rights reserved.