How to delete migration files in Rails 3

前端 未结 11 1105
盖世英雄少女心
盖世英雄少女心 2020-12-07 07:54

I would like to remove/delete a migration file. How would I go about doing that? I know there are similar questions on here but as an update, is there a better way than doin

11条回答
  •  广开言路
    2020-12-07 08:54

    None of these answers quite fit the problem i had as the migration i wanted to delete was missing: I had created and run a migration in some other branch, which was then discarded. The problem is when a migration is run, rails adds the version into a schema_migrations table in the database. So even if it isn't listed in your db structure or schema, rails looks for it. You can reveal these orphaned migrations by running:

    rails db:migrate:status

    Note the versions of the missing migrations and head into the db console:

    rails dbconsole

    Now remove the versions from the migration table manually:

    delete from schema_migrations where version='';

    You should now be good.

提交回复
热议问题