SQLException on db:test:load with Rails

有些话、适合烂在心里 提交于 2020-01-04 06:55:09

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/16741820/sqlexception-on-dbtestload-with-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!