Closed zjx17 closed 5 years ago
zjx@zjx-Superman:~/CourseSelect$ rake db:seed rake aborted! ActiveRecord::RecordInvalid: Validation failed: Email has already been taken /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/validations.rb:79:in `raise_record_invalid' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/validations.rb:43:in `save!' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/attribute_methods/dirty.rb:29:in `save!' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/transactions.rb:291:in `block in save!' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/transactions.rb:220:in `transaction' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/transactions.rb:348:in `with_transaction_returning_status' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/transactions.rb:291:in `save!' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/persistence.rb:51:in `create!' /home/zjx/CourseSelect/db/seeds.rb:128:in `block in <top (required)>' /home/zjx/CourseSelect/db/seeds.rb:127:in `each' /home/zjx/CourseSelect/db/seeds.rb:127:in `<top (required)>' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `load' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `block in load' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:240:in `load_dependency' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:268:in `load' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/railties-4.2.5.2/lib/rails/engine.rb:547:in `load_seed' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/tasks/database_tasks.rb:250:in `load_seed' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/activerecord-4.2.5.2/lib/active_record/railties/databases.rake:183:in `block (2 levels) in <top (required)>' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/gems/rake-11.2.2/exe/rake:27:in `<top (required)>' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/bin/ruby_executable_hooks:15:in `eval' /home/zjx/.rvm/gems/ruby-2.2.6@rails4252/bin/ruby_executable_hooks:15:in `<main>' Tasks: TOP => db:seed (See full trace by running task with --trace) My log: [0m [1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m [1m[35m (0.2ms)[0m BEGIN [1m[36mUser Exists (0.4ms)[0m [1mSELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('admin@test.com') LIMIT 1[0m [1m[35m (0.2ms)[0m ROLLBACK [1m[36m (0.1ms)[0m [1mBEGIN[0m [1m[35mUser Exists (0.3ms)[0m SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('teacher1@test.com') LIMIT 1 [1m[36m (0.1ms)[0m [1mROLLBACK[0m
rake db:migrate:reset rake db:seed
两次重复seed数据,会有相同的email被写入,而这个项目是不允许有相同的email的账号