数据库上的SQLException:test:使用Rails加载

我一直在研究一个小而复杂的Rails应用程序,它有多个has_and_belongs_to_many关系。 它是开源的,代码在这里。 一切工作正常,但最近我添加了新的HABTM关系迁移,并且rspec测试开始失败。 Rake:db:migrate正在工作(问题在本地工作),只是不在测试中。 运行db:test:load --trace时,出现以下错误:

: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 <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 <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初始化'/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 '/Users/ new' /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 / new' /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 / new' /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 / new' /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 / new' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in :91:in prepare'/ Users / og / .rvm / gems / ruby​​-1.9.3-head / gems / sqlite3-1.3.7 / lib / sqlite3 / database.rb:134:在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中执行'/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord -3.2.9 / lib / active_record / connection_adapters / abstract_adapter.rb:280: 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 /connection_adapters/ 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 : 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执行'/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:in in method_missing' create_table' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:466:in ruby- 1.9.3-head / gems / activerecord-3.2.9 / lib / active_record / migration.rb:438: block in say_with_time' /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/benchmark.rb:280:in /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ 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:in /Users/og/ say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in / say_with_time' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.9/lib/active_record/migration.rb:458:in method_missing'/ Users / og / Documents / websites /fermi/db/schema.rb:49: 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 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' 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 3.2 .9 / lib / active_record / schema.rb:50: define' /Users/og/Documents/websites/fermi/db/schema.rb:14:in '/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 /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport- load' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in在加载块中/Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb :236: load_dependency' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in '/Users/og/ load_dependency' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245: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_dependency' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245: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_dependency' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245: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_dependency' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245: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_dependency' /Users/og/.rvm/gems/ruby-1.9.3-head/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:245:in :in load'/ Users / og / .rvm / gems / ruby​​-1.9.3-head / gems / activerecord-3.2.9 / lib / active_record / railties / databases.rake:388: 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致电'/Users/og/.rvm/gems/ruby- 1.9.3-head@global/gems/rake-10.0.4/lib/r ake / task.rb:246:在block in execute' /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 in invoke_with_call_chain' execute' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:184:in 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:在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在执行块中执行'/Users/og/.rvm/gems/ruby-1.9.3 -head @全球/宝石/耙 -10.0.4 / lib / rake / task.rb:241:在each' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in执行'/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 og/.rvm/ block in invoke_with_call_chain' /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in ruby-1.9.3- block in invoke_with_call_chain' /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in lib/ruby/ block in invoke_with_call_chain' /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in monitor.rb:211: 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/ block in invoke_with_call_chain' /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in .rvm/ block in invoke_with_call_chain' /Users/og/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in 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' 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 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:在block in execute' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in每个'/ Users / og /.rvm/gems/ruby-1.9.3-head @ global / gems / rake-10.0.4 / lib / rake / task.rb:241: execute' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:184: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 in mon_synchronize' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:177:in 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: 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每个'/Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101 :在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_thr eads'/Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb: top_level' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:73:in '/Users/ top_level' /Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:73:in在运行块中运行/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运行中'/Users/og/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/bin/rake: 33:在<top (required)>' /Users/og/.rvm/gems/ruby-1.9.3-head/bin/rake:23:in og/.rvm/gems/ruby-1.9.3-head/bin/rake: <top (required)>' /Users/og/.rvm/gems/ruby-1.9.3-head/bin/rake:23:in载入'/Users/og/.rvm/gems/ruby-1.9 .3-head / bin / rake:23:在`'任务:TOP => db:schema:load

我的schema.rb文件如下:

# 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

任何帮助或信息将不胜感激。 我在网上搜索这些错误已经有一段时间了,但在网上很少发现。


对我来说有效的是删除schema.rb,这是模式定义文件。

(这个文件中的第一段注释建议删除它并生成一个新的,而不是编辑它。)

然后运行rake db:migrate ,执行所有迁移并重新创建schema.rb文件。


我也得到了类似的错误,我不知道。 但是,当我删除这些代码时,在这种情况下,

尝试删除这些行:

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

然后rake test:prepare可能工作。


将以下配置行添加到config/application.rbconfig/environments/development.rb

ActiveRecord::SchemaDumper.ignore_tables = /^sqlite_*/

这将忽略模式转储期间数据库中以“sqlite_”开头的所有表。

链接地址: http://www.djcxy.com/p/49941.html

上一篇: SQLException on db:test:load with Rails

下一篇: Rake aborted! Don't know how to build task 'up'