Rails 4 Remove Migration ID from Migration Index

Multi tool use
Rails 4 Remove Migration ID from Migration Index
How do I remove a migration ID listing with "** NO FILE **" in rake db:migrate:status? For example:
Status Migration ID Migration Name
--------------------------------------------------
up 20131017204224 Create users
up 20131218005823 ********** NO FILE **********
up 20131218011334 ********** NO FILE **********
I'm not understanding why it would still keep an old migration file when I manually removed it myself as I was playing around with how migrations work. Is this for record keeping? But what use is it when I don't have a name associated with it?
I tried using db:migrate:down command for those files but it says file missing. I have no clue what to do here.
Can someone explain how to remove this listing and maybe some insight on why this might happen.
3 Answers
3
You need to delete that numbers from your schema_migrations
table in the database.
schema_migrations
rake db:schema:dump
rake db:schema:load
If you want to have a migration number be deleted from the
schema_migrations
table, than just run rake db:rollback
to revert the migration, before deleting the file.– spickermann
Dec 20 '13 at 23:29
schema_migrations
rake db:rollback
But what if I already removed the file before I ran the
rake db:rollback
command?– Jay
Dec 20 '13 at 23:36
rake db:rollback
Than you did not follow Rails conventions. Shame on you. ;-)
– spickermann
Dec 20 '13 at 23:42
Ah crap.. I figured that would've been the answer. I only learned that after I started to tinker with migration commands : Ah well.. live and learn. Thanks for the help.
– Jay
Dec 21 '13 at 0:01
You deleted the file but the ID is still in the schema table.
Just Log into mysql
SELECT * FROM schema_migrations; *- take note of the version_id*
Then
DELETE FROM schema_migrations WHERE VERSION = version_id;
Then logout and verify
rake db:migrate:status
You can also delete it using SQL, but through the rails console.
sql = "DELETE FROM schema_migrations WHERE VERSION = 'version_id'"
ActiveRecord::Base.connection.exec_query(sql)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Not to sound like I want the answer to be spoon fed but after looking into schema_migrations.. I'm guessing I'm suppose to reload the schema for it to rebuild? I used this command
rake db:schema:dump
rake db:schema:load
but the no file listings are still there. I'm also guessing it's some kind of ActiveRecord::Schema method to delete a specific version in the database?– Jay
Dec 20 '13 at 23:20