【问题标题】:Rails Rake db:migrate aborting (sqlite3)Rails Rake db:迁移中止(sqlite3)
【发布时间】:2016-05-14 09:02:43
【问题描述】:

有人提出了类似的问题,但没有一个建议对我有用。我正在尝试在我的计算机上迁移 Rails 开发中的数据库,但我不断收到此错误消息:

 rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined local variable or method `total' for #<CreateProfessors:0x007f8ce3ca4e60>/Users/tfantina/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:664:in `block in method_missing'
   /Users/tfantina/.rvm/gems/ruby-2.2.1/gems/activerecord-   4.2.5.1/lib/active_record/migration.rb:634:in `block in say_with_time'
/Users/tfantina/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:634:in `say_with_time'
/Users/tfantina/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.5.1/lib/active_record/migration.rb:654:in `method_missing'

它持续了一百行左右。
这里的一篇帖子建议删除

null: false

来自

  t.timestamps null:false

我做到了。

我尝试过的另一个建议是运行 db:drop:all 然后 db:create:all 然后 db:migrate。

为了确保 sqlite3 在我的 OSX 上,我在终端中运行了 sqlite3 查询并返回:SQLite 版本 3.8.10.2 所以我认为它工作正常。

迁移失败:

    class CreateProfessors < ActiveRecord::Migration
  def change
    create_table :professors do |t|
      t.string :fname
      t.string :lname
      t.decimal :rating-total
      t.decimal :rating-hw
      t.decimal :rating-test
      t.decimal :rating-interest
      t.text :comments
      t.string :ease

      t.timestamps 
    end
  end
end

【问题讨论】:

  • 请粘贴上一次迁移或失败的迁移
  • 我添加了失败的迁移,这是我目前唯一完成的迁移。

标签: ruby-on-rails sqlite dbmigrate


【解决方案1】:

这些列名是非法的:

t.decimal :rating-total
t.decimal :rating-hw
t.decimal :rating-test
t.decimal :rating-interest

应该是:(使用_而不是-

t.decimal :rating_total
t.decimal :rating_hw
t.decimal :rating_test
t.decimal :rating_interest

【讨论】:

  • 嘿嘿!而已。谢谢,我是 Rails 的超级新手,所以这是非常基本的,但我很感激我真的被卡住了。
猜你喜欢
  • 1970-01-01
  • 2011-04-21
  • 2012-09-08
  • 2023-03-04
  • 1970-01-01
  • 2011-04-29
  • 2013-02-01
  • 2012-11-17
  • 1970-01-01
相关资源
最近更新 更多