Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 为什么“我的用户”表有无列错误?_Sql_Ruby On Rails_Ruby_Testing_Yaml - Fatal编程技术网

Sql 为什么“我的用户”表有无列错误?

Sql 为什么“我的用户”表有无列错误?,sql,ruby-on-rails,ruby,testing,yaml,Sql,Ruby On Rails,Ruby,Testing,Yaml,在控制台中运行测试后,我遇到以下错误: ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" user_test.rb: class UserTest < ActiveSupport::TestCase test "a user should enter a first name" do user

在控制台中运行测试后,我遇到以下错误:

ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users"
user_test.rb:

class UserTest < ActiveSupport::TestCase
  test "a user should enter a first name" do
    user = User.new
    assert !user.save
    assert !user.errors[:first_name].empty?
  end

  test "a user should enter a last name" do
    user = User.new
    assert !user.save
    assert !user.errors[:last_name].empty?
  end

  test "a user should enter a profile name" do
    user = User.new
    assert !user.save
    assert !user.errors[:profile_name].empty?
  end

  test "a user should have a unique profile name" do
    user = User.new
    user.profile_name = users(:adam).profile_name

    assert !user.save
    assert !user.errors[:profile_name].empty?
  end
end
database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
 adapter: sqlite3
 database: db/development.sqlite3
 pool: 5
 timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
我认为是我的用户迁移文件:

class DeviseCreateUsers < ActiveRecord::Migration
def change
  create_table(:users) do |t|
  t.string :first_name
  t.string :last_name
  t.string :profile_name

  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  t.integer  :sign_in_count, :default => 0
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, :default => 0 # Only if lock strategy is     :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at

  ## Token authenticatable
  # t.string :authentication_token


  t.timestamps
end

 add_index :users, :email,                :unique => true
 add_index :users, :reset_password_token, :unique => true
end
end
classdeveliecCreateUsersfalse,:default=>
t、 字符串:加密密码,:null=>false,:default=>
##可恢复
t、 字符串:重置密码\u令牌
t、 日期时间:重置密码发送时间
##难忘的
t、 datetime:记住在
##可追踪
t、 整数:计数中的符号,默认值=>0
t、 日期时间:当前登录时间
t、 日期时间:上次登录时间
t、 字符串:ip中的当前\u符号\u
t、 字符串:ip中的最后\u签名\u
##可证实
#t.string:确认令牌
#t.datetime:已确认
#t.datetime:确认发送至
#t.string:未确认的电子邮件#仅当使用可再确认
##可锁
#t.integer:failed_尝试,:default=>0#仅当锁定策略为:failed_尝试时
#t.string:unlock_token#仅当解锁策略为:email或:两者皆有时
#t.datetime:locked_在
##可认证令牌
#t.string:authentication\u令牌
t、 时间戳
结束
添加索引:users,:email,:unique=>true
添加索引:users,:reset\u password\u token,:unique=>true
结束
结束

我想知道是什么导致了错误,但更重要的是为什么。

我认为这里有两种可能性,但我将重点关注眼前的问题。如果您的Rake任务返回
未找到任何命令
,则可能是因为您的计算机上未安装Rake。我会从那里开始

要安装Rake,请在终端中键入:

gem install rake
代码不起作用的原因是用户表中没有名为
password
的列。使用
rakedb:migrate
rakedb:test:prepare
可以确保您创建的任何迁移都应用于您的数据库


让我知道结果。

我认为这里有两种可能性,但我将关注眼前的问题。如果您的Rake任务返回
未找到任何命令
,则可能是因为您的计算机上未安装Rake。我会从那里开始

要安装Rake,请在终端中键入:

gem install rake
代码不起作用的原因是用户表中没有名为
password
的列。使用
rakedb:migrate
rakedb:test:prepare
可以确保您创建的任何迁移都应用于您的数据库


让我知道结果。

在我看来,您的问题是,正如错误所说,您的用户表中没有密码列。您必须将其添加到迁移中:

t.string   :password

但是,请注意,我从未使用过Desive,因此在这方面我可能是错的。

在我看来,您遇到的问题是,正如错误所述,您的用户表中没有密码列。您必须将其添加到迁移中:

t.string   :password

但是,请注意,我从未使用过Desive,因此我在这一点上可能是错的。

当我从用户夹具中删除
密码
密码确认
列时,它顺利通过了测试。我的一位朋友告诉我,这可能是由于Desive的升级。

当我从用户设备中删除
密码
密码确认
列时,它通过了测试,没有出现错误。我的一位朋友告诉我,这可能是由于devise的升级。

我之前尝试过,并得到了一个“未找到的命令”
rake db:migrate
,然后
rake db:test:prepare
?仍然是一个“未找到的命令”?您是否在调用
rails控制台的目录中?你也可以发布你的
数据库.yml
以获取kicks吗?@jason328一个pwd检查显示我是。我之前试过了,得到了一个“command not found”怎么办
rake db:migrate
然后
rake db:test:prepare
?仍然是一个“command not found”你在你调用
rails控制台的目录中吗?你也可以发布你的
database.yml
来获得支持吗?@jason328一个pwd检查显示我是。这看起来很奇怪,因为我以前做过很多次rake db:migrate,都没有问题。我是否可以在控制台中输入命令以查看是否已安装?我试图安装,但得到了以下错误:错误:在执行gem时。。。(Errno::EACCES)权限被拒绝-/Users/Jadam/.rvm/gems/ruby-2.0.0-p0/gems/rake-10.0.4/.gemtestry
bundle show
并查看rake是否在将显示的列表中。但是如果您在之前运行它,则必须已经安装了它。出现错误的原因是您没有将
sudo
放在
gem安装rake
之前
Sudo
允许您在非root用户时运行命令。显示*rake(10.0.4)。我很确定我是root用户,因为我是这台笔记本电脑上唯一的用户。请尝试
bundle update
,然后运行rake任务。我没有办法了。希望其他人能启发我们。使用rake(10.0.4)的节目我猜这意味着它是当前的一个?之后是rake db:migrate和rake db:test:prepare,但在ruby-Itest test/unit/user_test.rb上仍然给出了相同的错误。这看起来很奇怪,因为我以前做过很多次rake db:migrate,都没有问题。我是否可以在控制台中输入命令以查看是否已安装?我试图安装,但得到了以下错误:错误:在执行gem时。。。(Errno::EACCES)权限被拒绝-/Users/Jadam/.rvm/gems/ruby-2.0.0-p0/gems/rake-10.0.4/.gemtestry
bundle show
并查看rake是否在将显示的列表中。但是如果您在之前运行它,则必须已经安装了它。你出错的原因是什么