【问题标题】:Rails lost migration file issueRails 丢失迁移文件问题
【发布时间】:2013-11-28 12:58:32
【问题描述】:

2 个月前,我的一个迁移文件已被删除。问题是当我在 localhost 中 rake db:migrate 我的数据库时,迁移丢失了。我无法创建新的迁移,因为生产数据库是用丢失的文件迁移的。因此,每次我在本地导入生产数据库并运行迁移时,它都会显示:

字段已存在....

我看到一些评论说我应该用相应版本的迁移文件修改 schema_migrations 表。

你对这个问题有更深入的解释吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby postgresql rails-migrations


    【解决方案1】:

    schema_migrations 表包含已运行的所有迁移的所有版本号,或者系统认为至少已运行的所有版本号。当您执行rake db:migrate 时,rails 会查看 db/migrate 中的所有文件,并忽略数字前缀在 schema_migrations 中的文件。

    因此,如果您有一个实际上已经运行的迁移,但系统认为它没有,您只需将其版本号添加到 schema_migrations 中。

    打开相关的数据库控制台,输入

    insert into schema_migrations (version) values("<the number from the start of the migration file>");
    

    显然,将中的部分替换为正确的数字。

    然后,db:migrate 将不再尝试运行该迁移。

    【讨论】:

      猜你喜欢
      • 2021-09-18
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 2018-06-09
      • 2015-08-30
      相关资源
      最近更新 更多