我的Rails应用程序有自己的MySQL数据库(并且需要mysql2gem),但是还需要连接某个特定模型的外部MongoDB数据库(因此我在Gemfile中包含了mongoid和bson_ext).现在,当我try 为新模型生成迁移时,它告诉我

$ rails g migration CreateLocations
       error  mongoid [not found]

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

数据库.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

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个)

Database相关问答推荐

如何使一个IP允许在运行GitHub操作到RDS数据库时,您不允许从外部访问数据库?

如何在 Angular 中使用 IndexedDB?

生产中的超大型 Mnesia 表

PostgreSQL 嵌套 INSERTs / WITHs 用于外键插入

时间数据库设计,有一个转折(live vs draft rows)

如何更改 Heroku 中的列类型?

如何最好地在 MS SQL Server 中复制整个数据库?

外键可以作为主键吗?

锁定机制(悲观/乐观)如何与数据库事务隔离级别相关?

按最强 LIKE 排序 SQL?

如何使用 INSERT ... ON CONFLICT ... 更新所有列?

在内存中创建 SQLite 数据库

Sqlite 和 Python - 使用 fetchone() 返回字典?

PHP 可以与 MS SQL 数据库一起使用吗

SQL全文搜索与LIKE

如何使用 django 判断 postgresql 数据库中是否存在某些内容?

在将字符串插入数据库期间单引号转义

SQL - 如何使用 MS SQL 2008 R2 备份数据库并导出为 MDF 文件

我应该在哪里存储外键?

从 SQLite 导出到 SQL Server