什么会导致迁移除了保留正确的版本之外什么也不做?

发布于 2024-12-20 09:27:56 字数 476 浏览 2 评论 0原文

我有一个应用程序,我首先在 Rails 3.1 中编写,但为了减少 Heroku 上的 slug 大小,我生成了一个新的 Rails 3.0.9 应用程序,并手动移动了必要的代码(或者我是这么认为的)。一个多月以来,一切都按预期工作,但我一直在使用 rake db:schema:load 因为我没有更改数据库模式。今天我尝试更改我的架构,但迁移没有执行任何操作。他们似乎认为他们正在运行并且正在跟踪版本,但我没有在控制台上得到任何输出,也没有对数据库进行任何更改,schema.rb 文件也没有更改。

rake db:migrate --trace 实际上说 ** 执行 db:schema:dump 作为最后一步,但 schema.rb 文件仍然没有我所在的列试图添加。有谁知道发生了什么事吗?该应用程序已连接到数据库,一切正常,我只是似乎无法运行任何迁移。我可以更改 schema.rb 文件并再次运行 rake:db:load 但我想避免丢失生产部署中的数据。

I have an app that I was first writing in rails 3.1 but in an effort to reduce my slug size on heroku I generated a new rails 3.0.9 app and manually moved over the necessary code (or so I thought). Everything worked as expected for over a month but i had been using rake db:schema:load because I hadn't changed the db schema. Today I tried to change my schema and migrations are doing nothing. They appear to think they are running and they are keeping track of versions but I get no output to the console and no changes to the db, also the schema.rb file is unchanged.

rake db:migrate --trace actually says ** Execute db:schema:dump as the last step, but the schema.rb file still does not have the column I was trying to add. Does anyone have any idea what is going on? The app is connected to a database, and everything is working fine I just can't seem to run any migrations. I could change the schema.rb file and run rake:db:load again but I would like to avoid losing data on the production deployment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贵在坚持 2024-12-27 09:27:56

Migrations for Rails 3.1 可以使用知道如何进行向上和向下迁移的 Migration#change 方法。在 3.0 中,您需要有单独的 Migration.upMigration.down 方法。您应该能够将 change 更改为 up,然后编写 down 部分。

正如 tee 所指出的,您需要确保将 def change 更改为 def self.updef self.down ,因为较旧的迁移方法是类方法而不是实例方法。

Migrations for Rails 3.1 can use a Migration#change method that knows how to do both an up and down migration. In 3.0, you'll need to have a separate Migration.up and Migration.down methods. You should be able to change the change to up and then write the down section.

As tee pointed out, you'll need to make sure to change def change to def self.up and def self.down since the older migration methods are class rather than instance methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文