Class 是一个保留字,所以我将表名从class_assignment
to更改cassignments
为避免任何可能导致它的错误(尽管我有class_instruction(s)
。我尝试了复数和单数版本,但仍然得到错误。cassignments
表是中间assignments
和之间的多对多关系表class_instructions
。
架构:
ActiveRecord::Schema.define(:version => 20130524160107) do
create_table "assignments", :force => true do |t|
t.string "name"
t.string "fractionRepresentations"
....etc...
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "cassiggnments", :force => true do |t|
t.integer "class_instruction_id"
t.integer "assignment_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "cassiggnments", ["assignment_id"], :name => "index_class_assignment_on_assignment_id"
add_index "cassiggnments", ["class_instruction_id"], :name => "index_class_assignment_on_class_instruction_id"
create_table "class_instructions", :force => true do |t|
t.string "name"
t.datetime "time"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "person_id"
end
add_index "class_instructions", ["person_id"], :name => "index_class_instructions_on_person_id"
....etc....
end
尝试在 seed.rb 中播种数据库
# ClassInstruction Assignment
cia1 = Cassignment.create({ class_instruction_id: 4, assignment_id: 1 }, :without_protection => true ).save!
我得到了错误:
rake aborted!
Could not find table 'cassignments'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/connection_adapters/sqlite_adapter.rb:465:in `table_structure'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `yield'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `default'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:243:in `column_defaults'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/base.rb:479:in `initialize'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `new'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `create'
/Users/special/dev/SoundOfFractions/db/seeds.rb:83:in `<top (required)>'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.2/lib/rails/engine.rb:520:in `load_seed'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:309:in `block (2 levels) in <top (required)>'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:252:in `block (2 levels) in <top (required)>'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/special/.rvm/gems/ruby-1.9.3-p362/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/special/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/Users/special/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:setup => db:seed
唯一奇怪的是,尽管我进行了迁移,但我没有得到cassignment.rb
模型,所以我不得不手动创建它(也许我没有使用脚手架,这是我通常习惯做的,但我离题了)。所以为了后代,这里是cassignment.rb
class Cassignment < ActiveRecord::Base
belongs_to :class_instruction
belongs_to :assignment
end
命名复数匹配其他多对多关系表和种子结构,但我不知道我哪里出错了,除了理解种子文件找不到表,根据sqlite浏览器确实存在,并且正确地称为cassignments
(复数)。