Closed igostavro closed 8 years ago
My best guess is that your schema defines "group_memberships"."member_id"
as an integer (the default), and your users
table defines its primary key as a uuid
rather than an integer. This causes a type mismatch.
Please let me know if that's what's going on.
thats it actually. What is the best course of action? Fix the migration for the group_memberships? If so can you provide code... new to ruby, sorry.
It kind of depends. the group_memberships
table holds membership information for all models, not just users. So all models that you plan to put into a group would have to have the same column type. If you really need uuid
, then group_memberships.member_id
will also need to be of type uuid
.
Another option you could explore is to make group_memberships.member_id
of type string. Postgres might be able to coerce a uuid into a string. The performance could get pretty bad if you have lots of memberships inserted over time.
ok i seemed to fix this with a migration:
class ChangeGroupMemberIdToUuid < ActiveRecord::Migration
def up
remove_column :group_memberships, :member_id
add_column :group_memberships, :member_id, :uuid
end
def down
remove_column :group_memberships, :metric_id
add_column :group_memberships, :member_id, :integer
end
end
Cool. You could also do:
class ChangeGroupMemberIdToUuid < ActiveRecord::Migration
def change
change_column :group_memberships, :member_id, :uuid
end
end
I actually tried that and got an error about not being able to coerce integer to uuid. Did you get a different result?
I see. I didn't try it. That error makes sense, since you can't convert an integer into a UUID. If your database is empty I would expect Postgres to just change the column and not complain about coercion.
Ah, makes sense, maybe I should have nuked the table before running the migration ;-)
Thanks for your help!
this code:
Causes the following crash:
Any ideas?