Rails 3 migrations: Adding reference column?

后端 未结 10 2086
余生分开走
余生分开走 2020-11-30 17:15

If I create a new rails 3 migration with (for example)

rails g migration tester title:tester user:references

, everything works fine...howe

10条回答
  •  無奈伤痛
    2020-11-30 17:42

    With the two previous steps stated above, you're still missing the foreign key constraint. This should work:

      class AddUserReferenceToTester < ActiveRecord::Migration
          def change
              add_column :testers, :user_id, :integer, references: :users
          end
      end
    

提交回复
热议问题