gpt4 book ai didi

sql - 为什么我的用户表没有列错误?

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:50 25 4
gpt4 key购买 nike

在控制台中运行测试后出现以下错误:

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

用户测试.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

用户.rb:

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

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :profile_name

validates :first_name, presence: true

validates :last_name, presence: true

validates :profile_name, presence: true,
uniqueness: true

has_many :statuses

def full_name
first_name + " " + last_name
end
end

用户.yml:

dan:
first_name: "Dan"
last_name: "Can"
email: "dan@email.com"
profile_name: "dan"
password: "123456"
password_confirmation: "123456"

数据库.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

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

最佳答案

当我从用户夹具中删除 passwordpassword_confirmation 列时,它通过了测试,没有出现任何错误。一位 friend 告诉我,这可能是由于设计升级所致。

关于sql - 为什么我的用户表没有列错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com