2011-12-30 32 views
1

rake db:seedを実行すると、何かが壊れています!RoR:SQLite3 :: ConstraintException:制約に失敗しました=> rake db:seed

私は次のエラーを取得する:

[email protected]:~/ticketee$ rake db:seed rake aborted! SQLite3::ConstraintException: constraint failed: INSERT INTO "users" ("admin", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Tasks: TOP => db:seed (See full trace by running task with --trace)

ここに私のseeds.rb:

admin_user = User.create(:email => "[email protected]", :password => "password") admin_user.admin = true

admin_user.confirm!

Project.create(:name => "Ticketee Beta")

ここに私の宝石-リスト:

> source 'http://rubygems.org' 
> 
> gem 'rails', '3.1.0' 
> 
> # Bundle edge Rails instead: 
> # gem 'rails',  :git => 'git://github.com/rails/rails.git' 
> 
> gem 'sqlite3' 
> 
> 
> # Gems used only for assets and not required 
> # in production environments by default. group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" gem 
> 'dynamic_form' gem 'uglifier' end 
> 
> gem 'jquery-rails' 
> 
> # Use unicorn as the web server 
> # gem 'unicorn' 
> 
> # Deploy with Capistrano 
> # gem 'capistrano' 
> 
> # To use debugger 
> # gem 'ruby-debug19', :require => 'ruby-debug' 
> 
> group :test, :development do # Pretty printed test output gem 
> 'rspec-rails', '~>2.7' end 
> 
> group :test do gem 'cucumber-rails' gem 'capybara' gem 
> 'database_cleaner' gem 'email_spec' gem 'factory_girl' end 
> 
> gem 'devise', '~> 1.4.3' gem 'cancan' 

を私は「すくいデシベルを実行すると:シード - トレース "

[email protected]:~/ticketee$ rake db:seed --trace 
** Invoke db:seed (first_time) 
** Invoke db:abort_if_pending_migrations (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Execute db:abort_if_pending_migrations 
** Execute db:seed 
rake aborted! 
SQLite3::ConstraintException: constraint failed: INSERT INTO "users" ("admin", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/statement.rb:108:in `step' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/statement.rb:108:in `block in each' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/statement.rb:107:in `loop' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/statement.rb:107:in `each' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:192:in `to_a' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:192:in `block in exec_query' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:171:in `exec_query' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/relation.rb:70:in `insert' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/persistence.rb:313:in `create' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/timestamp.rb:51:in `create' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/callbacks.rb:268:in `block in create' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:401:in `_run_create_callbacks' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/callbacks.rb:268:in `create' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/persistence.rb:294:in `create_or_update' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/callbacks.rb:264:in `block in create_or_update' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:399:in `_run_save_callbacks' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/callbacks.rb:264:in `create_or_update' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/persistence.rb:37:in `save' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/validations.rb:50:in `save' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/attribute_methods/dirty.rb:22:in `save' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:241:in `block (2 levels) in save' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:208:in `transaction' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:293:in `with_transaction_returning_status' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:241:in `block in save' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:252:in `rollback_active_record_state!' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/transactions.rb:240:in `save' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.4.9/lib/devise/models/confirmable.rb:38:in `block in confirm!' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.4.9/lib/devise/models/confirmable.rb:111:in `unless_confirmed' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.4.9/lib/devise/models/confirmable.rb:35:in `confirm!' 
/home/ray/ticketee/db/seeds.rb:12:in `<top (required)>' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `block in load' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.0/lib/rails/engine.rb:487:in `load_seed' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:299:in `block (2 levels) in <top (required)>' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/home/ray/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load' 
/home/ray/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>' 
Tasks: TOP => db:seed 

私のコードで何が起こったのか教えていただけますか?私は新しいです。

ありがとうございます。

+0

この行で何をしようとしていますか: "admin_user.admin = true admin_user.confirm!"私はこの行がエラーを引き起こしていると思います –

+0

私はこの行がエラーではないと思います。コードは<< Rails 3 in Action >>から来たものです。コードはhttps://github.com/JeskTop/ticketeeです。私はSQLite3が何か間違っていると思います。 – JeskTop

+0

私は何が起こっているのか知っています!なぜなら、SQLite3は同じデータを持っていたからです。 – JeskTop

答えて

2

私の推測では、あなたが呼び出すときに必要なすべてのフィールドを提供していないということです。

admin_user = User.create(:email => "[email protected]", :password => "password") 

テーブルのユーザーのためのマイグレーションファイルはどのようなものが見えますか? モデルユーザーに入力した検証は何ですか?

+0

私はこの行がエラーではないと思います。コードは<< Rails 3 in Action >>から来たものです。コードはhttps://github.com/JeskTop/ticketeeです。私はSQLite3が何か間違っていると思います。 – JeskTop

+0

私は何が起こっているのか知っています!なぜなら、SQLite3は同じデータを持っていたからです。ありがとうございました。 – JeskTop

0

私のモデルには 'has_many'検証があるので、トレース<top (required)>と同じエラーが発生しました。 has_manyまたはbelongs_toがusers.rbファイルのどこかにあり、を実行できないことを確認してください。コメントアウトしてシードし、コメントを外します。

1

テストを実行している間に私が挿入したレジスタがいくつかあったため、test.sqlite3、development.sqlite3、schema.rbファイルを削除して、移行したデータベースを実行してDBをシードしました。

関連する問題