I have a rails app with a number of has_many and belongs_to relations. I want to make sure that whenever a record with a belongs_to relation is saved that its foreign key has been set. Originally I created the foreign key column with NOT NULL to try to catch an insert that forgot to set the value. However, MySQL requires a valid default value, which ActiveRecord initializes new instances to. This causes no error on save, but will leave the foreign key pointing to nothing. Right now, I''ve changed the foreign key to allow null and made that value default. Then, I use validates_presence_of to check that it''s been set. However, it seems like there should be a better way to do it. Is there any simple way to enforce valid foreign keys on relations? validates_associated does not seem to help in this case.