gpt4 book ai didi

ruby-on-rails - RoR: SQLite3::ConstraintException: 约束失败 =>rake db:seed

转载 作者:行者123 更新时间:2023-12-01 11:03:21 25 4
gpt4 key购买 nike

当我运行 rake db:seed 时,有些东西坏了!

我收到以下错误:

ray@ray-virtual-machine:~/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 => "admin@ticketee.com", :password => "password") admin_user.admin = true

admin_user.confirm!

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

这是我的 gem list :

> 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'

当我运行“rake db:seed --trace”时

ray@ray-virtual-machine:~/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

你能告诉我我的代码中发生了什么吗?我是新手。

非常感谢您的宝贵时间。

最佳答案

我的猜测是您在调用时没有提供所有必填字段:

admin_user = User.create(:email => "admin@ticketee.com", :password => "password") 

用户表的迁移文件是什么样的?您对模型用户进行了哪些验证?

关于ruby-on-rails - RoR: SQLite3::ConstraintException: 约束失败 =>rake db:seed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8677607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com