Ruby on Rails를 처음 사용했습니다. 나는 마이그레이션 사용자레일 이주시 데이터베이스가 완전히 업데이트되지 않았습니다.
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.column :username, :string, :limit => 25, :default => "", :null => false
t.column :hashed_password, :string, :limit => 40, :default => "", :null => false
t.column :first_name, :string, :limit => 25, :default => "", :null => false
t.column :last_name, :string, :limit => 40, :default => "", :null => false
t.column :email, :string, :limit => 50, :default => "", :null => false
t.column :display_name, :string, :limit => 25, :default => "", :null => false
t.column :user_level, :integer, :limit => 3, :default => 0, :null => false
end
User.create(:username=>'test',:hashed_password=>'test',:first_name=>'test',:last_name=>'test',:email=>'[email protected]',:display_name=> 'test',:user_level=>9)
end
end
위에서 언급하지만, 테스트 데이터가 거기
mysql>select * from users;
Empty set (0.00 sec)
가 편집 난 그냥 떨어만큼 내가 rake db:migrate
테이블은 열이 생성을 실행 만들 라는이 전체 데이터베이스 및 마이 그 레이션을 다시 시작하고 지금은 다음과 같은 오류가 표시됩니다.
rake aborted!
An error has occurred, all later migrations canceled:
Can't mass-assign protected attributes: username, hashed_password, first_name, last_name, email, display_name, user_level
내가 뭘 잘못하고있어? 감사합니다.
'User.create! '(느낌표 사용)로 변경하면'User.create' 문이 유효성 검사 오류를 발생합니까? – zwippie
질문을 편집 해주세요. –
attr_accessible : username, : hashed_password, : first_name, : last_name, : email, : display_name, : user_level –