Mike Christensen
Mike Christensen

Reputation: 91724

Ruby on Rails ignores UUID columns during db:create

I'm trying to create a model with something like:

jobs title:string companyid:uuid

However, when I run db:create, it creates the table with the "title" column but just ignores the "companyid" column. The app of course crashes because ActiveRecord can't find the companyid column. If I add the DB column in manually, the app works (so I know RoR knows how to handle this data type)..

I'd like my DB provisioning and migration scripts to run correctly. I'm using PostgreSQL 9.0 and the postgres-pg adapter.

Anything special I need to do? Thanks!

Upvotes: 0

Views: 1897

Answers (1)

srboisvert
srboisvert

Reputation: 12759

This should help:

Ruby on Rails: UUID as your ActiveRecord primary key

Your migration isn't working because UUID isn't a supported type. If you look at the link you will see that they used UUID as a column name and string as the type. They also disabled the id column and set their UUID:string column to be the primary key.

There is also the simplified type in the Postgres Adapter that may be helpful for insight to why it works once you create the column manually. Though it just maps UUID to a string.

Fixing migrations so they could handle Postgres UUIDs could be some nice low hanging fruit for a contribution if someone having this issue wanted to contribute to Rails but given that Postgres UUIDs don't really appear to do much and your app will have to generate the IDs they might as well just be strings.

Upvotes: 4

Related Questions