Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Elliott Geier
Elliott Geier
10,169 Points

Adding uuid's to a table in my rails app.

I am currently writing an application that will create a blank photo object with only a uuid and creation date as a skeleton for when an actually photo is added to the object. However I am having trouble finding any information about uuid's on the internet. If anyone can lead me in the right direction would be appreciated.

I have already set my primary-key to uuid.. but when I use rails console and create a new picture object the uuid is not generated instead the default shows.

irb(main):007:0> Picture.create (0.0ms) begin transaction (0.0ms) rollback transaction => #<Picture id: nil, created_at: nil, updated_at: nil, uuid: "uuid_generate_v4()">

ActiveRecord::Schema.define(version: 20170307152118) do

create_table "photo_booths", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "booth_number" t.string "booth_location" t.integer "picture_count" end

create_table "pictures", id: nil, force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t. "uuid", default: "uuid_generate_v4()", null: false <--------------- t.index ["id"], name: "sqlite_autoindex_pictures_1", unique: true end


module Photobooth class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. config.generators do |generator| generator.orm :active_record, primary_key_type: :uuid <---------------- end end end

I have been stuck for a few hours now.. but I am new and dont know where to go