This error can be solved in many ways because there many reasons behind this error;
Duplication of the table:
Always make sure that the table does not exist already. This can be done in the following steps;
- Type- rails dbconsole
- Type – tables (Check to see if there is an error during the rake db: migrate that has the table name like, create_table(: test) rake aborted!)
- If you see the table name after running the .tables in the console type then drop table TABLENAME;
- Then .quit to go back to branch again and run the rake db: migrate command again.
- Another option of resetting the whole database - use with caution! Reset all the data as well – bundle exec rake db:migrate: reset
For making sure you are running everything in the same development environment;
RAILS_ENV=development bundle exec rake db:migrate:reset
RAILS_ENV=development bundle exec rails s
- Go to the database.
- Click the schema_migration table. You can see the migration list;
- Sort the versions columns and find the latest migrations if you want to go back.
- Delete or insert the new one.
- Rails can keep all the migration history in this table. So, you can adjust the migration history according to your requirement.