尝试获取我的 spree 应用程序的示例数据。使用以下步骤:
bundle exec rake railties:install:migrations
bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec rake spree_sample:load
但在 上bundle exec rake db:seed
,会引发以下错误:
loading ruby /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/db/default/spree/countries.rb
rake aborted!
ActiveRecord::StatementInvalid: SQLite3::SQLException: near ",": syntax error: INSERT INTO spree_countries ("name", "iso3", "iso", "iso_name", "numcode", "states_required")
VALUES ('Andorra', 'AND', 'AD', 'ANDORRA', '020', 't') .. ('Zimbabwe', 'ZWE', 'ZW', 'ZIMBABWE', '716', 't');
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in initialize' /usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:innew'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in prepare' /usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:inexecute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in block in execute' /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:inblock in log'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:in instrument' /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:467:inlog'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:in execute' /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/db/default/spree/countries.rb:24:in'
/usr/local/rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in require' /usr/local/rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:inrequire'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in block in require' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in require' /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:11:inblock (2 levels) in '
/usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:30:in block (3 levels) in <top (required)>' /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:24:ineach'
/usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:24:in block (2 levels) in <top (required)>' /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/db/seeds.rb:5:in'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in load' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inblock in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in load_dependency' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/engine.rb:547:in load_seed' /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/railtie.rb:194:inpublic_send'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/railtie.rb:194:in method_missing' /home/aparna/my_store/db/seeds.rb:10:in'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in load' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inblock in load'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in load_dependency' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/engine.rb:547:in load_seed' /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:250:inload_seed'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:180:in block (2 levels) in <top (required)>' SQLite3::SQLException: near ",": syntax error /usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:ininitialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in new' /usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:inprepare'
/usr/local/rvm/gems/ruby-2.2.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in execute' /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:inblock in execute'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in block in log' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/notifications/instrumenter.rb:20:ininstrument'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:467:in log' /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/connection_adapters/sqlite3_adapter.rb:329:inexecute'
/usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/db/default/spree/countries.rb:24:in <top (required)>' /usr/local/rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:inrequire'
/usr/local/rvm/gems/ruby-2.2.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in require' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:inblock in require'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in load_dependency' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:inrequire'
/usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:11:in block (2 levels) in <top (required)>' /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:30:inblock (3 levels) in '
/usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:24:in each' /usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/lib/tasks/core.rake:24:inblock (2 levels) in '
/usr/local/rvm/gems/ruby-2.2.1/gems/spree_core-3.0.2/db/seeds.rb:5:in <top (required)>' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in block in load' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in load' /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/engine.rb:547:inload_seed'
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/railtie.rb:194:in public_send' /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/railtie.rb:194:inmethod_missing'
/home/aparna/my_store/db/seeds.rb:10:in <top (required)>' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:inload'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in block in load' /usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:inload_dependency'
/usr/local/rvm/gems/ruby-2.2.1/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in load' /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.3/lib/rails/engine.rb:547:inload_seed'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:250:in load_seed' /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:180:inblock (2 levels) in '
Tasks: TOP => db:load_dir
(See full trace by running task with --trace)
知道该怎么办吗?
答案1
哦,狂欢。
国家/州种子文件中生成的 SQL 语句有问题。
这是我的替代品,虽然速度慢,但有效
spree_core/db/default/spree/countries.rb
require 'carmen'
Carmen::Country.all.map do |country|
name = country.name
iso3 = country.alpha_3_code
iso = country.alpha_2_code
iso_name = country.name.upcase
numcode = country.numeric_code
states_required = country.subregions?
# country_inserts << [name, iso3, iso, iso_name, numcode, states_required].join(", ")
Spree::Country.new( :name => name,
:iso3 => iso3,
:iso => iso,
:iso_name => iso_name,
:numcode => numcode,
:states_required => states_required
).save!
end
canada = Spree::Country.find_by(iso: "CA")
Spree::Config[:default_country_id] = canada.id
和
spree_core/db/default/spree/states.rb
connection = ActiveRecord::Base.connection
state_inserts = []
Spree::Country.where(states_required: true).each do |country|
carmen_country = Carmen::Country.named(country.name)
carmen_country.subregions.each do |subregion|
name = connection.quote subregion.name
abbr = connection.quote subregion.code
country_id = connection.quote country.id
state_inserts << [name, abbr, country_id].join(", ")
Spree::State.new(:name => name, :abbr => abbr, :country_id => country_id).save!
end
end
答案2
Spree 的规格通常使用最新的 SQLite 版本。我猜这个问题没有被发现,因为我们从未测试过 3.7.11 之前的版本。我想这个问题实际上是 SQLite DB 过时了。我看不出 Spree 想要支持旧版本的 SQLite。
我猜你的数据库是 3.7.11 之前的版本。如果是,你能更新它吗?