PENGZhaoqing / CourseSelect

校园选课系统样本 (a template for course selection system by Ruby on Rails)
https://courseselect.herokuapp.com/
MIT License
106 stars 205 forks source link

rake db:seed rake aborted! Email has already been taken #80

Closed zjx17 closed 5 years ago

zjx17 commented 7 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
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT "schema_migrations".* FROM "schema_migrations"
   (0.2ms)  BEGIN
  User Exists (0.4ms)  SELECT  1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('admin@test.com') LIMIT 1
   (0.2ms)  ROLLBACK
   (0.1ms)  BEGIN
  User Exists (0.3ms)  SELECT  1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('teacher1@test.com') LIMIT 1
   (0.1ms)  ROLLBACK
PENGZhaoqing commented 7 years ago
rake db:migrate:reset
rake db:seed

两次重复seed数据,会有相同的email被写入,而这个项目是不允许有相同的email的账号