Adding foreign key to a rails model

The currently accepted answer on this isn’t really accurate as it doesn’t add a database foreign key. It’s just adding integer columns. In Rails 4.2.x, the current approach is: http://guides.rubyonrails.org/active_record_migrations.html#foreign-keys Create a migration: rails generate migration migration_name For existing columns, in the migration add the foreign keys like this: class MigrationName < ActiveRecord::Migration def change … Read more

Could not load file or assembly ‘Microsoft.Build.Framework'(VS 2017)

I believe I had the same issue as you did. I didn’t save the whole error message, but my error message was ‘Could not load file or assembly ‘Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.‘ I am using Visual Studio 2017 and was trying to do … Read more

Run a single migration file

Assuming fairly recent version of Rails you can always run: rake db:migrate:up VERSION=20090408054532 Where version is the timestamp in the filename of the migration. Edit: At some point over the last 8 years (I’m not sure what version) Rails added checks that prevent this from running if it has already been run. This is indicated … Read more