加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 设置默认数据库连接Rails

发布时间:2020-12-16 19:52:01 所属栏目:百科 来源:网络整理
导读:我的rails应用程序有自己的 MySql数据库(并且需要mysql2 gem),但也需要与一个特定模型的外部MongoDB数据库连接(因此我在Gemfile中包含了mongoid和bson_ext).现在,当我尝试为一个新的模型生成一个迁移时,它告诉我 $rails g migration CreateLocations error m
我的rails应用程序有自己的 MySql数据库(并且需要mysql2 gem),但也需要与一个特定模型的外部MongoDB数据库连接(因此我在Gemfile中包含了mongoid和bson_ext).现在,当我尝试为一个新的模型生成一个迁移时,它告诉我
$rails g migration CreateLocations
       error  mongoid [not found]

当我生成位置模型时,它包含了Mongoid :: Document,所以Rails显然认为它正在使用外部数据库作为主数据库.

databse.yml:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: associalize_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

mongoid.yml:

development:
  host: pearl.mongohq.com
  port: 27019
  username: asfasdf
  password: sadfasdf
  database: app4574678

test:
  host: pearl.mongohq.com
  port: 27019
  username: asdfadhasdfa
  password: hadsadfas
  database: app4574678

production:
  host: pearl.mongohq.com
  port: 27019
  username: asdfdfsasda
  password: afdasdfdasdf
  database: app4574678

UPDATE
使用Mongo的模型

class ExternalMongoModel
  include Mongoid::Document

  field :title
  field :long_title
  field :deal_type
  field :merchandise_type
  field :market_id
  field :market_name
  field :market_location,type: Array
  field :featureType
  field :country_code
  field :subtitle
  field :offer_ends_at
  field :price
  field :value
  field :merchant_type
  field :content
  field :merchant

  index(
    [[:division_latlon,Mongo::GEO2D]],background: true
  )

end

解决方法

将其添加到config / application.rb中的应用程序块中:
config.generators do |g|
  g.orm :active_record
end

(找到的解决方案here)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读