【问题标题】:performing sql operation in rails console在 Rails 控制台中执行 sql 操作
【发布时间】:2014-05-28 10:45:17
【问题描述】:

我在我的 Rails 应用程序中安装了gem 'sqlite3'。 在哪里我是否执行查询以检查表中是否存在某些记录。

在我的 Rails 控制台中,我运行了sqlite3。

C:\Sites\iAuth>sqlite3
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from users;
Error: no such table: users
sqlite>

我有一个用户表,但它为什么说不存在这样的表。我将Devise 用于authentication。下面是我的模型。

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

【问题讨论】:

  • 您的数据库存储在哪里?
  • 你跑rake db:migrate了吗?
  • 是的,我确实运行了我的 rake db:migrate。

标签: ruby-on-rails ruby sqlite devise


【解决方案1】:

您可能需要直接引用您的 db 文件:

sqlite3 db/development.sqlite3

【讨论】:

    【解决方案2】:

    你在找这个命令吗?

    rails dbconsole
    

    在这个控制台你可以直接运行sql查询

    【讨论】:

      猜你喜欢
      • 2015-10-28
      • 1970-01-01
      • 2019-03-06
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多