Can I add the migration file, but tell rails not to run it locally? I need the file for others to setup the application locally.
Asked
Active
Viewed 1,824 times
3
-
I think it depends on if you already ran the migration or not. So did you have it at one point and it got deleted? If so, you could figure out the timestamp for that file and just add it back into the db/migrate folder. – Magicmarkker Nov 30 '12 at 21:39
-
This sounds like a hack. Why don't you want it to run locally, but run on others to set up? If you don't want it to run because it has already run locally, then this is exactly what migrations are intended to do (they run only if needed). If you modified the tables directly (i.e. from SQL prompt) then the solutions below should work. But if there's some different reason, then this is a very fragile solution. – Tom Harrison Nov 30 '12 at 22:03
-
@TomHarrisonJr I ran it locally, but then the original migration file got deleted somehow... Some of my migrations are a mess basically because I've been experimenting with different ways to do the same thing to find the best way. – Brian McDonough Nov 30 '12 at 22:19
2 Answers
5
If you have a file:
db/migrate/20121010100909_modify_table_x.rb
You can go into your database and run the following SQL.
MySQL:
INSERT INTO 'schema_migrations' VALUES ('20121010100909');
PostgreSQL:
INSERT INTO schema_migrations VALUES ('20121010100909');
And it will then ignore that migration.
Edit - How to "go into your database"
Using the parameters from config/database.yml
in Rails, connect to the database you are using.
You will need to use the command-line tool of whatever database software you're using. E.g.
For PostgreSQL:
psql -d <database_name> -U <username>
For MySQL:
mysql -u <username> <databasename>@localhost -p
Type in your password if required.
Then type in and execute the SQL above.

mccannf
- 16,619
- 3
- 51
- 63
-
Ok, thanks. When you say "go into your database," is there a command I run to access the DB? Not familiar with that, but sounds like I should look into it. I'm running PG. – Brian McDonough Nov 30 '12 at 22:22
-
1
-
1You can use psql
on the terminal . If you get to the prompt like yourdatabase=# , you can check what tables it contains by typing \dt . You'll see the table 'schema_migrations' and you can type the sql statement , mentioned by mccannf (don't forget the ';' at the end ) – R Milushev Nov 30 '12 at 22:42 -
Using postgres, there should be no quotes around schema_migrations. Thank you for the quick answer. – Brian McDonough Nov 30 '12 at 22:55
-
0
You could insert the proper timestamp into the schema_migrations table locally.

John Naegle
- 8,077
- 3
- 38
- 47