ruby on rails undefined方法用于活动记录

时间:2009-12-08 09:08:18

标签: ruby-on-rails ruby activerecord rake

(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:migrate

命令..在我的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。

1 个答案:

答案 0 :(得分:2)

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

t.column :first_name, :string

语法。