多对一关联转换为职位 [英] Many to one association converting to postres
问题描述
我正在将Rails应用程序从sqlite转换为postgres,以便可以与heroku一起部署。我已经安装了postgres并进行了迁移,但是当我尝试运行查询以查找与房屋相关的所有室友时,出现以下错误
I am in the process of converting a rails app form sqlite to postgres so that I can deploy with heroku. I have postgres installed and I ran migrations, however when I try to run a query to find all the housemates associated with a house I get the following error
PG::Error: ERROR: operator does not exist: character varying = integer
LINE 1: SELECT COUNT(*) FROM "mates" WHERE "mates"."house_id" = 1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(*) FROM "mates" WHERE "mates"."house_id" = 1
此错误源自注册视图,您在添加房屋后将其重定向到创建视图并成为管理员。这是视图代码:
This error originates form a sign-up view that you are redirected to to create and administrator after adding a house. Here is the view code:
Extracted source (around line #4):
1: <div class="container">
2: <div class="row">
3: <div class="span5 offset3">
4: <% if current_house.mates.empty? %>
5: <h2>Add an Administrator</h2>
6: <% else %>
7: <h2>Add a New Housemate</h2>
感谢所有帮助!
推荐答案
转到 add_house_id_to_mates
迁移并将第3行从字符串更改为整数。
之后,删除 20130628212206_change_type_of_house_id_in_house.rb
迁移。
Go to add_house_id_to_mates
migration and change line 3 from string to integer.
After this, remove the 20130628212206_change_type_of_house_id_in_house.rb
migration.
从零开始运行迁移:
rake db:drop db:create db:migrate
这篇关于多对一关联转换为职位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!