Search code examples
ruby-on-railsdatabase-migrationrails-migrations

How to fix previously renamed and Override existing migration


I have two models first is Course and another is Lesson. First we have table course_lessons with migration xxxxxxxx_course_lessons with some fields after that I have rename this course_lessons table to lessons. It is working fine for me. But After that I have again add course_lesseons table create migration and override the existing migration and because of that my next all migration break.

How can I fix this migration error?

Thanks in advance


Solution

  • I think your best option for now is dropping your database and migrations and start over again. It's better to not rename migrations. If you have a migration runned and you don't like it, you can do a rollback with: rake db:rollback this will rollback your database to the previous version.(this will not put back tables if you delete them!) Once you did a rollback, you can rename the migration and run: rake db:migrate again.

    Another option would be to delete all the migration files. If the database is good for now, anyone else who starts the project can load the database from schema with: rake db:schema:load