Search code examples
ruby-on-railsvariablesmethodsundefineddbmigrate

Rails db:migrate aborted with "undefined local variable or method `limit'" why?


Sorry for my English. I searched the site, but I could not find a solution. When I try to make rails db: migrate gives me this error:

C:\PW\Sites\grota>rails db:migrate
== 20170209014957 CreateWholesalers: migrating     ================================
-- create_table(:wholesalers)
-- limit()
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

undefined local variable or method `limit' for #    <CreateWholesalers:0x00000006bfc6a0>
C:/PW/Sites/grota/db/migrate/20170209014957_create_wholesalers.rb:7:in     `block in change'
C:/PW/Sites/grota/db/migrate/20170209014957_create_wholesalers.rb:3:in     `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
NameError: undefined local variable or method `limit' for #    <CreateWholesalers:0x00000006bfc6a0>
C:/PW/Sites/grota/db/migrate/20170209014957_create_wholesalers.rb:7:in     `block in change'
C:/PW/Sites/grota/db/migrate/20170209014957_create_wholesalers.rb:3:in     `change'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

here is my migrate code:

class CreateWholesalers < ActiveRecord::Migration[5.0]
  def change
    create_table :wholesalers do |t|
      t.string "brand_name", :limit => 25
      t.string "username", :limit => 25
      t.string "password_digest"
      t.string "email", limit => 50
      t.decimal "latitude"
      t.decimal "longitude"
      t.timestamps
    end
  end
end

Thank you in advance.


Solution

  • This line is causing the error (missing :):

    t.string "email", :limit => 50