与 rails 中的外部数据库连接相关

Related to External database connectivity in rails

使用 database.yml 链接外部 mysql 数据库后,还安装了 mysql2 和 activerecord-mysql2-adapter gem。

当我运行rails db:schema:dump

架构如下所示。

Schema.rb

# 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 that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do

  # Could not dump table "employees" because of following NoMethodError 
  #   undefined method `sql_type' for "int(11)":String

end

而且当我 运行 rails db:schema:dump:

时,我 运行 也遇到了这个问题

/home/admin/.rvm/gems/ruby-2.4.2/gems/activerecord-mysql2-adapter-0.0.3/lib/active_record/connection_adapters/mysql2_adapter.rb:606: warning: constant ::Fixnum is deprecated

database.yml

development: &default
adapter: mysql2
encoding: utf8
pool: 5
host: localhost
username: Ruby
password: *****
port: 3306
socket: /var/lib/mysql/mysql.sock
database: rubyappdb

问题出在 activerecord-mysql2-适配器 gem 上。 在 Gemfile 中将其注释掉并 运行 bundle install 解决了这个问题。 希望以后不会有什么问题。