[英]Spree Could not find table 'spree_countries'
I have cloned a existing Spree project on Rails 3.2.17. 我已经在Rails 3.2.17上克隆了一个现有的Spree项目。
Rake db:create works but when running migrate, seed or rails s I run into this error. Rake db:create可以运行,但是在运行迁移,种子或Rails时,我遇到了此错误。
Could not find table 'spree_countries'
I have tried 我努力了
rake db:reset
and various spree generators but all give back the same error. 和各种狂欢生成器,但都返回相同的错误。
This is the error I got when like OP I did anything with Rake: 这是当我像OP一样对Rake做任何事情时遇到的错误:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:
relation "spree_countries" does not exist
The most common solution for setting the country in Spree is the following: 在Spree中设置国家/地区最常见的解决方案如下:
config/initializers/spree.rb 配置/初始化/ spree.rb
Spree.config do |config|
country = Spree::Country.find_by_name('Mexico')
config.default_country_id = country.id if country.present?
end
This will work fine until you drop the database and try to recreate it - and do not overwrite config/initializers/spree.rb . 在删除数据库并尝试重新创建数据库之前,此方法将正常工作, 并且不要覆盖config / initializers / spree.rb 。
Overwrite .../config/initializers/spree.rb? (enter "h" for help) [Ynaqdh] n
While recreating the database the Country table is not available and you hit the Could not find table 'spree_countries' error. 重新创建数据库时,“国家/地区”表不可用,并且您遇到“ 找不到表'spree_countries”错误。 It's nasty because the initialization code that causes the bug works for a while and it is only much later the error arises when you decide to drop the database. 这很讨厌,因为导致该错误的初始化代码可以工作一段时间,并且仅在很久以后,当您决定删除数据库时,该错误才会出现。
The code suggested on google groups was to find the country_id and assign it - you can puts
the id out or use an SQL query on spree_countries . 在Google网上论坛上建议的代码是查找country_id并为其分配-您可以puts
ID放在外面或在spree_countries上使用SQL查询。
config/initializers/spree.rb 配置/初始化/ spree.rb
Spree.config do |config|
# Sets default country to Mexico
config.default_country_id = 157
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.