AlSayed Gamal
AlSayed Gamal

Reputation: 139

ruby on rails undefined method(s) for active record

(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)

I get that error when I'm issuing the

rake db:migrate

command .. in the root folder of my rails project ..

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

Note: that I also used the integer and text fields and it didn't work .. Error always changes to undefined datatype {string, integer, text ,...} based on the typed in the migration file .. ! Note: I'm using the rake db:migrate in the root folder of the app.

Upvotes: 0

Views: 6270

Answers (1)

alex.zherdev
alex.zherdev

Reputation: 24164

Check your version of rails. This "t.string" syntax came to rails when the Sexy Migrations plugin was merged into the core. If you cannot upgrade to the latest version, you should use

t.column :first_name, :string

syntax.

Upvotes: 3

Related Questions