When you run:
rake db:migrate
the only files that are being processed are those in db/migrate/ right?
Well since relationships such as one-to-one, one-to-many and many-to-many are defined in the in app/models/ , how does Rails enforce such relationships? After I do my migration and look at the generated database schema, I can’t see any foreign key constraints. So it’s confusing to me as to how all this works.
Quite simply it doesn’t.
It’s due to having to support multiple databases. Some, such as sqlite, don’t support foreign keys.
To add foreign keys you have to execute the raw SQL for them.