Ruby on Rails: adding columns to existing database Ruby on Rails: adding columns to existing database ruby ruby

Ruby on Rails: adding columns to existing database


As Speransky suggested, you should never modify old migration files. Rather you should create a new migration that adds the desired column. For instance, in this case you would run the following command in your app to create the new migration:

rails generate migration AddListIdColumnToIdeas list_id:integer

And Rails would generate the migration file automatically and the only thing left to do is run rake db:migrate.

If you insist on modifying the old migration file, you can add the column as you did and run the following:

rake db:droprake db:createrake db:migrate

Which will destroy your current database, create a new one and run all the migrations (which will include your new column).


If you want to add a new column to an exist database, you should use rails generate migration. So you can try rails generate migration add_list_id_to_ideas list_id:integer and then use rake db:migrate to commit this change.


You should not add new rows to old migrations. Migration is a step of building database. And number of last executed migration is stored in schema, and it will not be run or redone if you use will use rake db:migrate. If you run the migration with creating the table before, then you should create new migration where you may use add_column method.