【问题标题】:ruby on rails undefined method(s) for active record用于活动记录的 ruby​​ on rails 未定义方法
【发布时间】:2009-12-08 09:08:18
【问题描述】:
(in /Users/sayedgamal/apps/test)
/Users/sayedgamal/apps/test/config/boot.rb:20:Warning: Gem::SourceIndex#search support for String patterns is deprecated
== CreatePeople: migrating ====================================================
-- create_table(:people)
rake aborted!
undefined method `string' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x238e97c>

(See full trace by running task with --trace)

我在发布时遇到了这个错误

rake db:迁移

命令 .. 在我的 rails 项目的根文件夹中 ..

migrate/001_create_people.rb contents :
class CreatePeople < ActiveRecord::Migration
  def self.up
    create_table :people do |t|
     t.string :first_name
     t.string :second_name
     t.string :company
     t.string :email
     t.string :phone
    end
  end

  def self.down
    drop_table :people
  end
end

注意:我也使用了整数和文本字段,但它不起作用.. 错误总是更改为未定义的数据类型 {string, integer, text ,...} 根据在迁移文件中键入的内容..! 注意:我在应用程序的根文件夹中使用 rake db:migrate。

【问题讨论】:

    标签: ruby-on-rails ruby activerecord rake


    【解决方案1】:

    检查您的 rails 版本。当 Sexy Migrations 插件被合并到核心中时,这个“t.string”语法就出现了。如果无法升级到最新版本,则应使用

    t.column :first_name, :string
    

    语法。

    【讨论】:

    • 肯定是,看迁移数。我认为这两个成语同时改变了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多