无法更新 Rails 数据库迁移中的记录
例如,我有以下迁移
class AddStatusField < ActiveRecord::Migration
def self.up
add_column :tasks, :status, :string
Task.update_all "status='complete'", "completed = 't'"
remove_column :tasks, :completed
end
end
当我运行此命令(使用 rake db:migrate)时,我收到以下消息
== AddStatusField: migrating =================================================
-- add_column(:tasks, :status, :string)
-> 0.0010s
-- update_all("status='complete'", "completed = 't'")
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `update_all' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0xd3d34a8>
如果我立即运行迁移,它会再次出现 update_all
调用工作。
我正在使用 Rails 2.3.5 和 sqlite3。
什么给?
For example I have the following migration
class AddStatusField < ActiveRecord::Migration
def self.up
add_column :tasks, :status, :string
Task.update_all "status='complete'", "completed = 't'"
remove_column :tasks, :completed
end
end
When I run this (using rake db:migrate
) I get the following message
== AddStatusField: migrating =================================================
-- add_column(:tasks, :status, :string)
-> 0.0010s
-- update_all("status='complete'", "completed = 't'")
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `update_all' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0xd3d34a8>
If I immediately run the migration it again the update_all
calls appear to work.
I'm using Rails 2.3.5 and sqlite3.
What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来可能与
Task
命名冲突。应用程序中的任何其他类都会失败,还是只是Task
会失败?您可以使用
::Task
来调用它,以表明您希望在根命名空间中使用Task
类。例如,Rake 定义了自己的Task
类,并且迁移过程中的某些操作可能会执行相同的操作。It looks like it might be a naming conflict with
Task
. Does it fail with any other class in your application or justTask
?You might be able to call it using
::Task
to indicate that you want theTask
class in the root namespace. Rake, for example, defines its ownTask
class and it's possible that something in the migration process is doing the same.尝试
在 update_all 之前添加
Try adding
right before your update_all