如果我删除迁移文件会影响heroku吗?
我想我可能已经删除了一个迁移文件 - 我有很多迁移文件,因为我经常更改我的表。
我想知道这是否会影响我的 heroku 部署。我的 heroku rake db:migrate
以前工作正常,但现在停止工作了。
heroku 还告诉我一个表已经存在并中止了 rake 任务。
我需要重写丢失的迁移文件吗?
感谢您的帮助,我真的很感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,我认为您无法重写迁移..当然,除非您知道迁移文件名的日期戳是什么。如果您查看 db 文件夹中迁移文件的文件名,您会发现它们都带有日期戳。
该日期戳实际上存储在您要写入的数据库的字段中。如果您检查数据库,您会注意到一个“schema_migrations”表,您将在其中找到已运行的所有迁移的日期戳。
如果您不断删除迁移文件,迁移就会变得很棘手。如果可以的话,我会尽量不要删除较旧的迁移,特别是如果它们已经推送到您的数据库。如果您已经将它们推送到数据库,那么创建一个新的迁移文件来修复数据库会更容易,而不是继续回到旧的迁移和重构..尝试这样做会给你带来巨大的痛苦..
在你把它拆开之前,在尝试修复你的迁移之前在本地备份你的heroku数据库
如果你没有尚未将已删除的迁移文件推送到heroku分支,并且您只使用最后一个迁移文件,请先尝试回滚heroku中的最后一个迁移,修复您的迁移,将其推回并重试。
如果您已经尝试过这种方式但仍然遇到问题,您可以执行以下操作。但请注意!您看到的错误是因为您尝试将已存在的表推送到数据库。如果你把力=>在新迁移上添加 true 标签,您可以有效地将其推送到数据库,但实际上您将删除现有表并创建一个新表,因此旧表中的所有数据都将丢失。但是,如果您对此感到满意并且有信心不会破坏任何内容,那么您始终可以在迁移的顶部使用类似的东西。
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
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.
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..