ruby - PG::UndefinedTable: 错误: 关系 "cities" 不存在第 8 行: WHERE a.attrelid = '"cities"'::regclass ^
问题描述
我是 Sinatra 的新手,并试图创建一个发布请求,该请求会将一些数据添加到 PGadmin 的“城市”表中。但是,尝试添加它时出现错误。获取请求工作正常,在 post 端点上发布静态数据也工作正常,但发布数据不是我不确定出了什么问题,因为迁移和城市模型确实存在。这是代码:
城市.rb
class City < UserDB
validates_presence_of :name, :pin
def as_json(options = {})
super({only: [:city, :pin]})
end
end
移民:
class CreateCity < ActiveRecord::Migration[6.0]
def change
create_table :city do |t|
t.string :name
t.integer :pin
end
end
end
module Users
module V1
class CityController< LocalAPI::ApplicationBase
before do
content_type 'application/json'
end
get '/' do
city=City.all
if city
"city exists"
else
"doesn't exist"
end
end
post '/add' do
params = JSON.parse request.body.read
@name= params['name']
@pin= params['pin']
@city=City.new(name:@name,pin:@pin)
if @city.save
return output(200, @city.as_json)
else
"cant create"
end
end
end
end
end
我正在尝试通过邮递员发布以下内容:
{
"name": "hamilton",
"pin":"222"
}
请注意,路由已配置,当我访问 url 时它确实有效。也跑过db:migrate
解决方案
推荐阅读
- css - 引导卡 - 更改宽度
- python - 使用命令行实用程序的 python 子进程启动 Docker
- c - C、如何从队列中删除元素?
- python - 用于从网站下载文件的python脚本
- recursion - 为什么我们不能用 Opal 中使用 <~> 的代码替换 "many" 的 def?
- python - Mac:libGL.so.1:无法打开共享对象文件:没有这样的文件或目录
- javascript - 无法读取未定义的属性“toString” - Javascript
- html - 将 ngfor 数据移到其标签之外
- react-native - ReacNative:在 UIManager 中找不到 requireNativeComponent:“CKCameraManager”
- github - bazel 同步请求 github 登录并失败