SQLException on db:test:load with Rails - ruby-on-rails-3

I've been working on a small but somewhat complex Rails application with multiple has_and_belongs_to_many relationships. It's open source, and the code is here. Everything was working fine, but recently I added a new HABTM relationship migration, and an rspec test started to fail. Rake:db:migrate was working (and the issue was working locally), just not in testing. Upon running db:test:load --trace , I get the following error:
:fermi og$ rake db:test:load --trace /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/yaml.rb:56:in
<top (required)>': It seems your ruby installation is missing psych
(for YAML output). To eliminate this warning, please install libyaml
and reinstall your ruby.
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load rake aborted! SQLite3::SQLException: object name reserved for internal use: sqlite_sp_functions: CREATE TABLE
"sqlite_sp_functions" ("name" text, "text" text)
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in
initialize'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in
new'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in
prepare'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:in
execute'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in
block in execute'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:280:in block in log'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in
instrument'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract_adapter.rb:275:in log'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/connection_adapters/sqlite_adapter.rb:278:in
execute'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:in
create_table'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:466:inblock in method_missing'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:438:in block in say_with_time'
/Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/benchmark.rb:280:in
measure'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:438:in say_with_time'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:inmethod_missing' /Users/og/Documents/websites/fermi/db/schema.rb:49:in
block in <top (required)>'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/schema.rb:50:in
instance_eval'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/schema.rb:50:in
define' /Users/og/Documents/websites/fermi/db/schema.rb:14:in'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in
load'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in
block in load'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in
load_dependency'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in
load'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:388:in
block (3 levels) in <top (required)>'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:246:in
call'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:246:in
block in execute'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:241:in
each'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:241:in
execute'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:184:in
block in invoke_with_call_chain'
/Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:177:in
invoke_with_call_chain'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:170:in
invoke'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:499:in
block (3 levels) in '
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:246:in
call'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:246:in
block in execute'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:241:in
each'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:241:in
execute'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:184:in
block in invoke_with_call_chain'
/Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:177:in
invoke_with_call_chain'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:170:in
invoke'
/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:479:in
block (3 levels) in <top (required)>'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:246:in
call'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:246:in
block in execute'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:241:in
each'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:241:in
execute'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:184:in
block in invoke_with_call_chain'
/Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:177:in
invoke_with_call_chain'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/task.rb:170:in
invoke'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:143:in
invoke_task'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:101:in
block (2 levels) in top_level'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:101:in
each'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:101:in
block in top_level'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:110:in
run_with_threads'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:95:in
top_level'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:73:in
block in run'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:160:in
standard_exception_handling'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/lib/rake/application.rb:70:in
run'
/Users/og/.rvm/gems/ruby-1.9.3-head#global/gems/rake-10.0.4/bin/rake:33:in
<top (required)>' /Users/og/.rvm/gems/ruby-1.9.3-head/bin/rake:23:in
load' /Users/og/.rvm/gems/ruby-1.9.3-head/bin/rake:23:in `'
Tasks: TOP => db:schema:load
My schema.rb file is the following:
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130519192155) do
create_table "distributions", :force => true do |t|
t.float "mean"
t.float "spread"
t.float "wideness"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "operation_id"
t.string "type"
t.string "name"
end
create_table "distributions_models", :id => false, :force => true do |t|
t.integer "distribution_id"
t.integer "model_id"
end
create_table "distributions_operations", :id => false, :force => true do |t|
t.integer "distribution_id"
t.integer "operation_id"
end
create_table "models", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "operations", :force => true do |t|
t.string "operator"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "sqlite_sp_functions", :id => false, :force => true do |t|
t.text "name"
t.text "text"
end
# Could not dump table "sqlite_stat1" because of following StandardError
# Unknown type '' for column 'tbl'
# Could not dump table "sqlite_stat3" because of following StandardError
# Unknown type '' for column 'tbl'
create_table "sqlite_vs_links_names", :id => false, :force => true do |t|
t.text "name"
t.text "alias"
end
create_table "sqlite_vs_properties", :id => false, :force => true do |t|
t.text "parentType"
t.text "parentName"
t.text "propertyName"
t.text "propertyValue"
end
create_table "sqlite_vsp_diagrams", :id => false, :force => true do |t|
t.text "name"
t.text "diadata"
t.text "comment"
t.text "preview"
end
end
Any help or information would be much appreciated. I've search these errors online for quite a while, but have found very little online.

What worked for me was to delete schema.rb, which is the schema definition file.
(The first paragraph of comments within this file recommends deleting it and generating a new one, rather than editing it.)
Then just run rake db:migrate, which performs all the migrations and re-creates the schema.rb file.

I got the similar error either and I have no idea. But when I delete those code, in this case,
try delete these line:
create_table "sqlite_sp_functions", :id => false, :force => true do |t|
t.text "name"
t.text "text"
end
# Could not dump table "sqlite_stat1" because of following StandardError
# Unknown type '' for column 'tbl'
# Could not dump table "sqlite_stat3" because of following StandardError
# Unknown type '' for column 'tbl'
create_table "sqlite_vs_links_names", :id => false, :force => true do |t|
t.text "name"
t.text "alias"
end
create_table "sqlite_vs_properties", :id => false, :force => true do |t|
t.text "parentType"
t.text "parentName"
t.text "propertyName"
t.text "propertyValue"
end
create_table "sqlite_vsp_diagrams", :id => false, :force => true do |t|
t.text "name"
t.text "diadata"
t.text "comment"
t.text "preview"
end
then rake test:prepare might work.

Add the following config line to config/application.rb or in config/environments/development.rb:
ActiveRecord::SchemaDumper.ignore_tables = /^sqlite_*/
This will ignore all tables starting with "sqlite_" in your database during the schema dump.

Related

Database associations causing issues in db migration with postgres

I've been making a basic schema for a rails app but when I try to migrate it using rails db:migrate, it gives me some weird association errors that I'm not sure what's causing.
== 20211001092658 CreateDevelopers: migrating =================================
-- create_table(:developers)
-> 0.0076s
== 20211001092658 CreateDevelopers: migrated (0.0077s) ========================
== 20211001093122 CreateMessages: migrating ===================================
-- create_table(:messages)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "teams" does not exist
/home/nero/Projects/SMS-Rails/db/migrate/20211001093122_create_messages.rb:3:in `change'
Caused by:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "teams" does not exist
/home/nero/Projects/SMS-Rails/db/migrate/20211001093122_create_messages.rb:3:in `change'
Caused by:
PG::UndefinedTable: ERROR: relation "teams" does not exist
/home/nero/Projects/SMS-Rails/db/migrate/20211001093122_create_messages.rb:3:in `change'
Tasks: TOP => db:migrate
I've been having a few issues setting up Postgres on my machine but I figured most of it would be solved after I created the role, password and database.
Migration files:
#developers
class CreateDevelopers < ActiveRecord::Migration[6.1]
def change
create_table :developers do |t|
t.string :full_name
t.string :email
t.string :mobile
t.timestamps
end
end
end
#teams
class CreateTeams < ActiveRecord::Migration[6.1]
def change
create_table :teams do |t|
t.string :name
t.string :dept_name
t.string :dev_ids, array: true, default: []
t.timestamps
end
end
end
#messages
class CreateMessages < ActiveRecord::Migration[6.1]
def change
create_table :messages do |t|
t.references :team, null: false, foreign_key: true
t.string :title
t.text :content
t.timestamps
end
end
end

Rails seed.rb can't find table that exists in schema and SQL

Class is a reserved word, so I have changed the table name from class_assignment to cassignments to avoid any chance that that is the error causing it (despite me having class_instruction(s). I have tried plural and singular versions, and still get the error. The cassignments table is a middle table for the many to many relationship between assignments and class_instructions.
Schema :
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
Trying to seed the db in the seed.rb
# ClassInstruction Assignment
cia1 = Cassignment.create({ class_instruction_id: 4, assignment_id: 1 }, :without_protection => true ).save!
and I get the error:
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
The only strange thing is that despite my migrations, I didn't get a cassignment.rb model, so I had to manually create that (maybe I didn't use scaffold, what I am normally used to doing, but I digress). So for posterity, here is the cassignment.rb
class Cassignment < ActiveRecord::Base
belongs_to :class_instruction
belongs_to :assignment
end
naming pluralization matches other many to many relationship tables, and seed structures, but I have no clue where I am going wrong, other than the understanding that the seed file can't find the table, that does exist according to the sqlite browser, and is correctly called cassignments (plural).
You've created a table called cassiggnments with two 'g's
Is this a has_and_belongs_to_many relationship or a has_many :through relationship?
HABTM only:
In the former case you don't need the model and it's important that the table name be both of the joining table names in alphabetical order. assignments_class_instructions
In both cases, the correct approach to creating a join is to add instances of one class to instances of the other rather than creating the joins directly.
class_instruction = ClassInstruction.find(4)
class_instruction.assignments << Assignment.find(1)
Also, there is no problem with class_assignments and ClassAssignment as table and model names, so that isn't the issue.

rake migrate aborted for undefined local variable or method

Got a issue when i run rake db:migrate. The mistake message is like
-- create_table(:addresses)
-> 0.1792s
-- contact_id()
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined local variable or method `contact_id' for #<CreateAddresses:0x00000001724718>/var/lib/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/migration.rb:465:in `block in method_missing'
And i used command before migrate
rails g model address street:string city:string region:string postalcode:string country:string contact_id:integer
And my migration file :
class CreateAddresses < ActiveRecord::Migration
def change
create_table :addresses do |t|
t.string :street
t.string :city
t.string :region
t.string :postalcode
t.string :country
t.integer :contact_id
t.timestamps
end
add_index :addresses, [contact_id, :create_at]
end
end
Could anybody tell where i made mistake please? Thank you a lot.
you are missing : before contact_id:
add_index :addresses, [:contact_id, :create_at]

rake db:rollback of a recent migration hangs

I have a rails app that I wrote originally in rail 3, and upgraded to rails 3.1.10 about a month ago. I just created a habtm association between stories and tags, along with the related db migrations.
class Story < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :tags, :uniq => true
end
class Tag < ActiveRecord::Base
has_and_belongs_to_many :stories, :uniq => true
end
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.string :name
t.timestamps
end
end
end
class CreateStoriesTags < ActiveRecord::Migration
def change
create_table :stories_tags, :id => false do |t|
t.references :story, :tag
end
add_index :stories_tags, [:story_id, :tag_id]
end
end
And finally, here is the relevant schema.db:
create_table "stories", :force => true do |t|
t.string "title"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "stories", ["user_id"], :name => "index_stories_on_user_id"
create_table "stories_tags", :id => false, :force => true do |t|
t.integer "story_id"
t.integer "tag_id"
end
add_index "stories_tags", ["story_id", "tag_id"], :name => "index_stories_tags_on_story_id_and_tag_id"
create_table "tags", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
I migrated the DB and then played around with the associations in the console. Now I want to rollback the migration so to add some additional columns to the tags table. (I know that I could simply create a new migration, but I would still want to understand why I'm facing this problem.) Now, when I insert rake db:rollback into the console here is the initial output:
[nw0.0.1master (development)]$ rake db:rollback
== CreateStoriesTags: reverting ==============================================
-- drop_table(:stories_tags)
So far so good, but then the rake task just hangs . . . for hours. If I ctrl-c out of it here is the output to the console:
^Crake aborted!
An error has occurred, this and all later migrations canceled:
Interrupt: : ROLLBACK
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:605:in `async_exec'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:605:in `block in execute'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract_adapter.rb:245:in `block in log'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activesupport-3.1.10/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract_adapter.rb:240:in `log'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:604:in `execute'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `rollback_db_transaction'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `rescue in transaction'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/connection_adapters/abstract/database_statements.rb:182:in `transaction'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/transactions.rb:208:in `transaction'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:742:in `ddl_transaction'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:686:in `block in migrate'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:671:in `each'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:671:in `migrate'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:553:in `down'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:627:in `move'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/migration.rb:541:in `rollback'
/.rvm/gems/ruby-1.9.2-p290#rails3firstgemset/gems/activerecord-3.1.10/lib/active_record/railties/databases.rake:232:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:rollback
(See full trace by running task with --trace)
Couple of things to note, as this app started out w/ rails 3.0, all early migrations use the older Class.up Class.down methods to define the migrations. Also, when I first expirienced the hanging I switched the CreateStoriesTags migration to use up and down instance methods, but everything still hung.
UPDATE AND THE ANSWER
I noticed that the PGAdmin3 Workbench was also hanging. So, I restarted the Mac and now the rollbacks are working just find.
Turned out to be a problem with my db server. A simple restart fixed the problem

rake aborted after rake db:migrate

I was having issues migrating databases with mysql and decided to blow the whole thing out of the water and use postgres. I have it installed correctly along with the databases but now I'm getting the same errors I along the lines of when I was using mysql.
$ rake db:migrate
rake aborted!
/Users/beach180/rails_projects/app/db/migrate/20120114221528_create_users.rb:6: syntax error, unexpected ':', expecting keyword_end
t.string "email" :default => "", :null => false
This is the rb file
class CreateUsers < ActiveRecord::Migration
def up
create_table :users do |t|
t.string "first_name", :limit => 25
t.string "last_name", :limit => 50
t.string "email" :default => "", :null => false
t.string "password", :limit => 40
t.timestamps
end
end
def down
drop_table :users
end
end
Got any ideas?
You're missing a comma after the string "email".
t.string "email", :default => "", :null => false
^ comma