When we call
bundle exec db:migrate
Does it always create a new table? Or just create new columns that are not in the previous table?
And what does rollback do? How does it know which column to delete and is this deleting thing reversible? For example, if I accidentally deleted a useful column, can I cancel the previous action and get it back?
I assume you mean,
bundle exec rake db:migrateActive Record tracks which migrations have already been run. Example: If you are using sqlite3 as Database you can look at the table –
schema_migrationswhich has these migration details. It mostly has entries likeThis rake task just runs what you have in the migration files under
<app>/db/migrate/.So, if you have creation of tables in that migration file, it would do that.
To Rollback the last migration you can always run
rake db:rollbackFor a better understanding, I request you to read this Guide on Rails Migrations. Reading through it would resolve all your queries w.r.t migrations.