开发者

if i delete a migration file will it affect heroku?

I think I may have deleted a migration file - I have quite a few as I have been changing my tables a lot.

I'm wondering if this will affect my heroku deploy. my heroku rake db:migrate was working fine before but now has stopped working.

heroku is also telling me that a table already exists and aborts the rake task.

Will I need to re-write the missing migration file(s)?

thanks for any help, I really appreciate it开发者_Go百科.


No, I don't think you'll be able to re-write the migration.. unless of course you know what the datestamp was for the migration filename. If you look at the filenames of your migration files in your db folder you'll notice that they're all datestamped.

This datestamp is actually stored in a field in the database you're writing to. If you check out your database you'll notice a 'schema_migrations' table and in there you'll find the datestamps of all of the migrations you've already run.

Migrations are tricky things if you keep deleting migration files. I'd try not to delete older migrations if you can, especially if they're already pushed to your database.. If you have already pushed them to a database it's easier if you create a new migration file to fix your database rather than going back into old migrations and refactoring.. it'll cause you a world of pain trying to do it this way..

Before you go pulling it apart, make a backup of your heroku database locally before trying to fix your migrations

heroku db:pull

If you haven't already pushed your deleted migration files to your heroku branch and you're only playing with your last migration file, try rolling back your last migration in heroku first, fix your migration, push it back and try again.

heroku rake db:rollback

If you've tried it that way and you're still running into problems you can do the following. But be warned!! The error you're seeing is because you're trying to push a table to your database that already exists. If you put the force => true tag on your new migration you can effectively push it to your database, but you will actually be dropping the existing table and creating a new one so any data in your old table will be lost. But if you're ok with it and confident you're not going to break anything you can always use something like this in the top of your migration..

create_table "table_name", :force => true do |t|
     t.column "name",  :string....  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜