我在创建新鲜数据库后运行迁移时出现错误。迁移错误PG :: UndefinedTable:错误:关系“用户”不存在
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates_presence_of :first_name, :last_name, :phone
has_many :projects
has_many :items
def full_name
"#{first_name} #{last_name}"
end
scope :find_by_fullname, -> (fullname) {
self.all
.select{ |u| u if u.full_name.parameterize == fullname}
.first }
end
错误是由范围find_by_fullname饶人, 的错误是
PG::UndefinedTable: ERROR: relation "users" does not exist
LINE 8: WHERE a.attrelid = '"users"'::regclass
请任何人建议如何解决这个问题。
请仔细阅读问题,运行迁移,我创建了新的数据库运行后新移民。我知道当前的错误,但第一次发生这种情况时,我认为rake db:migrate首先加载模式,代码(范围)是为用户提供的,这就是为什么。不知道问题在哪里。 – iamsonivivek
在这种情况下,请检查是否有任何迁移,在任何'模型“上触发查询。 –
如果可能,您可以通过更改时间戳或将用户迁移迁移到用户表来移动向下迁移 –