【问题标题】:Related to External database connectivity in rails与 Rails 中的外部数据库连接相关
【发布时间】:2018-01-29 17:52:28
【问题描述】:

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

当我运行rails db:schema:dump

Schema 如下所示。

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

数据库.yml

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

【问题讨论】:

  • 显示你的 database.yml 文件
  • 添加请检查

标签: ruby-on-rails external database-schema mysql2


【解决方案1】:

问题出在 activerecord-mysql2-adapter gem 上。 在 Gemfile 中注释掉它并运行 bundle install 解决了这个问题。 希望以后不会出问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 2023-01-03
    • 2021-02-26
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多