我使用的是Ruby 2.2.2和Rails 4.2.3。
我做的命令是:
rails generate scaffold User name:string email:string
bundle exec rake db:migrate
我得到的错误是:
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `strong' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000005b72028>/home/clemant/tutorials/test2/db/migrate/20150709221657_create_users.rb:5:in `block in change'
我的迁移文件:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.strong :email
t.timestamps null: false
end
end
end
我的database.yml文件是:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
知道如何解决这个问题吗?
答案 0 :(得分:1)
在您的迁移文件中,您已撰写:t.strong :email
。
应该纠正如下:
t.string :email