Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.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
Ruby on rails ActiveRecord::语句无效:Rails中的PG::UnfinedColumn_Ruby On Rails - Fatal编程技术网

Ruby on rails ActiveRecord::语句无效:Rails中的PG::UnfinedColumn

Ruby on rails ActiveRecord::语句无效:Rails中的PG::UnfinedColumn,ruby-on-rails,Ruby On Rails,因此,完全错误是: 失败/错误:@region=region.find_by!url\u name:params[:id]ActiveRecord::Statement无效:PG::UnfinedColumn:错误:列区域。url\u name不存在第1行:选择区域。*来自区域所在的区域。url\u name 作为一个失败的例子,我得到: rspec./spec/controllers/regions\u controller\u spec.rb:15 regions controller sh

因此,完全错误是:

失败/错误:@region=region.find_by!url\u name:params[:id]ActiveRecord::Statement无效:PG::UnfinedColumn:错误:列区域。url\u name不存在第1行:选择区域。*来自区域所在的区域。url\u name

作为一个失败的例子,我得到:

rspec./spec/controllers/regions\u controller\u spec.rb:15 regions controller show应呈现显示页面

在我的区域控制器中,我有:

def show
 @region = Region.find_by!(url_name: params[:id])
 @careers = @region.careers
end
对于我的区域等级库控制器,我有:

describe 'show' do
it 'should render the show page' do
  region = Region::Create.run(FactoryBot.attributes_for(:region)).result
  get :show, params: { id: region.url_name }
  expect(response).to have_http_status :success
end

it 'should return a 404 error' do
  get :show, params: { id: 1 }
  expect(response).to have_http_status :not_found
end
end
在区域模型中,我有:

class Region < ApplicationRecord
 scope :ordered, -> { order(name: :desc) }
 scope :search, ->(term) { where('name LIKE ?', "%#{term}%") }
 has_many :locations, dependent: :destroy
 has_many :careers, through: :locations
 validates :name, presence: true
end

因此该列存在。页面使用url\u名称加载。然而,这是一个错误,告诉我该列不存在…?

因此,架构中似乎存在url\u名称,但另一个人删除了迁移文件。为了解决这个问题,我运行了删除列迁移,然后执行了添加列迁移,解决了这个问题

是否可以尝试迁移测试数据库,或者如果已启用Spring,请将其关闭并再次打开?已尝试迁移并运行测试。同样的问题。尝试关闭弹簧,运行测试。同样的问题。尝试关闭、打开弹簧,运行测试。同样的问题。好的,你能检查一下测试数据库Postico,pgAdmin中的实际表,看看列是否在那里吗?只是为了确认,url\u名称是在开发中找到的,而不是在测试中?创建表区域id bigint not NULL,名称字符变化,在没有时区的时间戳处创建\u not NULL,在没有时区的时间戳处更新\u not NULL,url\u名称字符变化;如果这是您的测试数据库,它应该可以工作。仔细检查database.yml文件,确保它指向正确的数据库。
create_table "regions", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "url_name"
end