Adding a column to an existing table in a Rails migration

后端 未结 11 1799
借酒劲吻你
借酒劲吻你 2020-11-28 00:34

I have a Users model which needs an :email column (I forgot to add that column during the initial scaffold).

I opened the migration file and added

11条回答
  •  离开以前
    2020-11-28 01:01

    You can also do

    rake db:rollback
    

    if you have not added any data to the tables.Then edit the migration file by adding the email column to it and then call

    rake db:migrate
    

    This will work if you have rails 3.1 onwards installed in your system.

    Much simpler way of doing it is change let the change in migration file be as it is. use

    $rake db:migrate:redo
    

    This will roll back the last migration and migrate it again.

提交回复
热议问题