 <p>Adding <code>belong_to</code> and <code>has_many</code> lines to your models makes Rails aware of their relationship and generates helper methods, but does not create FKs at the database level. To do that, you need to create and run a migration:</p> <pre><code>rails g migration add_level_id_to_students level_id:integer </code></pre> <p>then rake db:migrate</p> <p>If you want to generate a model with the foreign key part of it, you can use the <code>references</code> shortcut: <code>rails g model Student name:string level:references</code></p> <p>Check out the <a href="http://guides.rubyonrails.org/migrations.html" rel="nofollow">Rails guides</a> for more information!</p>