简体   繁体   English

使用mysql在RDS上的db:schema:dump。 错误:由于以下针对“ int(11)”的未定义方法“类型”,无法转储表“”:字符串

[英]db:schema:dump on RDS with mysql. Error: Could not dump table “” because of following NoMethodError undefined method `type' for “int(11)”:String

Setup: 设定:

rails: 4.2.5.1 导轨:4.2.5.1
ruby: 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32] 红宝石:2.2.4p230(2015-12-16修订版53155)[i386-mingw32]
windows 7 environment Windows 7环境

database.yml: database.yml:

default: &default
  adapter: mysql2
  encoding: utf8
  database: "database"
  username: "name"
  password: "password"
  host: "host"
  port: 3306 

development:
  adapter: mysql2
  encoding: utf8
  database: "database"
  username: "name"
  password: "password"
  host: "host"
  port: 3306

I am trying to use an existing mysql database on RDS. 我试图在RDS上使用现有的mysql数据库。 I created a new project using 我使用创建了一个新项目
rails new "app" and then attempted to get the database schema. rails new "app" ,然后尝试获取数据库模式。 When I run 当我跑步
ruby bin\\rake db:schema:dump the output in my schema.rb file is filled with the same error for every table in the database: ruby bin\\rake db:schema:dump我的schema.rb文件中的输出对于数据库中的每个表都充满了相同的错误:

ActiveRecord::Schema.define() do
# Could not dump table "test" because of following NoMethodError
#   undefined method `type' for "int(11)":String
end

I first thought that maybe it was because int(11) was a 64 bit integer, but later learned that the "11" in int(11) refers to the display size, and that it is still a 32 bit integer. 我最初以为是因为int(11)是64位整数,但是后来才知道int(11)中的“ 11”是指显示尺寸,它仍然是32位整数。

Can anyone explain why this is happening or why ruby doesn't recognize the 32 bit integer type for the primary key column. 谁能解释这种情况的发生或为什么ruby无法识别主键列的32位整数类型。

i think you have a field named "type" in your database. 我认为您在数据库中有一个名为“类型”的字段。 "type" is a reserved word in rails(sepecially for database). “类型”是rails中的保留字(特别是对于数据库)。

Solution : change the name of this field 解决方案:更改此字段的名称

Ex: "type" => "typemore" 例如:“ type” =>“ typemore”

check this 检查这个

I managed to get rid of this error by making the following changes to my Gemfile. 通过对我的Gemfile进行以下更改,我设法摆脱了这个错误。

gem 'mysql2', '~>0.3.13'
#gem 'activerecord-mysql2-adapter'

Then I ran bundle install to update my gems. 然后,我运行bundle install以更新我的宝石。

I am still not sure why this worked. 我仍然不确定为什么这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM