什么会导致迁移除了保留正确的版本之外什么也不做?
我有一个应用程序,我首先在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Migrations for Rails 3.1 可以使用知道如何进行向上和向下迁移的
Migration#change
方法。在 3.0 中,您需要有单独的Migration.up
和Migration.down
方法。您应该能够将change
更改为up
,然后编写down
部分。正如 tee 所指出的,您需要确保将
def change
更改为def self.up
和def 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 separateMigration.up
andMigration.down
methods. You should be able to change thechange
toup
and then write thedown
section.As tee pointed out, you'll need to make sure to change
def change
todef self.up
anddef self.down
since the older migration methods are class rather than instance methods.