Reputation: 13
So I was stupid and deleted all the rows in the schema_migration of my sqlite3 database. How do I fix this? Did I destroy my whole project?
Upvotes: 1
Views: 806
Reputation: 4136
So long as you don't need to run rake db:migrate
again you'll be fine. Otherwise you'll run into problems.
I probably should do this in Ruby, but i'm more familiar with Perl - so here's a quick script that'll help you resurect the schema_migrations table
!#/usr/bin/perl
opendir(DH, 'path/to/rails/app/db/migrate');
while($filename = readdir(DH))
{
next unless $filename =~ /\.rb$/;
@parts = split("_", $filename);
print "INSERT INTO schema_migration VALUES (" . $parts[0] . ");\n";
}
running the script will give you a series of insert statements that'll then be able to copy and paste into the sqllite command line tool
Upvotes: 1
Reputation: 16006
or you can just kill the DB and restart
rake db:drop; rake db:migrate; rake db:test:prepare
Upvotes: 0
Reputation: 45325
Did you delete db\schema.rb or db\migrate files too?
In the first case you can try move db file to other location and execute:
rake db:migrate
If you removed schema.rb and migration files you can execute
rails generate migration
and recreate migration manually.
Upvotes: 2