错误:列mysql rails超出范围值

时间:2022-06-17 16:20:30

I have sql table:

我有sql表:

-- Table structure for rb_amazon_daily
-- ----------------------------
DROP TABLE IF EXISTS `rb_amazon_daily`;
CREATE TABLE `rb_amazon_daily` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date DEFAULT NULL,
  `book_title` varchar(255) DEFAULT NULL,
  `marketplace` varchar(255) DEFAULT NULL,
  `amazon_kdp_avg_list_price` decimal(12,10) DEFAULT NULL,
  `amazon_kdp_royalty_type` varchar(255) DEFAULT NULL,
  `amazon_kdp_revenue_in_usd` decimal(13,13) DEFAULT NULL,
  `amazon_kdp_royalty_in_usd` decimal(13,13) DEFAULT NULL,
  `amazon_kdp_paid_downloads` int(11) DEFAULT NULL,
  `amazon_kdp_free_downloads` int(11) DEFAULT NULL,
  `amazon_ku_pages_read` int(11) DEFAULT NULL,
  `amazon_ku_revenue_in_usd` decimal(12,10) DEFAULT NULL,
  `create_space_revenue_in_usd` decimal(12,10) DEFAULT NULL,
  `create_space_royalty_in_usd` decimal(12,10) DEFAULT NULL,
  `create_space_paperbacks_sold` int(11) DEFAULT NULL,
  `daily_total_revenue` decimal(12,10) DEFAULT NULL,
  `daily_total_royalty` decimal(12,10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=301 DEFAULT CHARSET=latin1;

错误:列mysql rails超出范围值 And I have

我有

class AmazonDaily < ActiveRecord::Base
    self.table_name = "rb_amazon_daily"
end

But then when I try to save somedata to database

但是当我尝试将一些数据保存到数据库时

#<AmazonDaily:0x007fffef743a00
 id: nil,
 date: Sat, 16 Jul 2016,
 book_title: "Catalyst Moon: Incursion",
 marketplace: "Amazon.com",
 amazon_kdp_avg_list_price: 0.299e1,
 amazon_kdp_royalty_type: "70%",
 amazon_kdp_revenue_in_usd: 0.598e1,
 amazon_kdp_royalty_in_usd: 0.408e1,
 amazon_kdp_paid_downloads: 2,
 amazon_kdp_free_downloads: 0,
 amazon_ku_pages_read: 0,
 amazon_ku_revenue_in_usd: 0.0,
 create_space_revenue_in_usd: 0.0,
 create_space_royalty_in_usd: 0.0,
 create_space_paperbacks_sold: 0,
 daily_total_revenue: 0.598e1,
 daily_total_royalty: 0.408e1>

I got an error: Error: Out of range value for column `

我收到一个错误:错误:列`超出范围值

home/jonsdirewolf/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.9/lib/mysql2/client.rb:120:in _query': Mysql2::Error: Out of range value for column 'amazon_kdp_revenue_in_usd' at row 1: INSERT INTOrb_amazon_daily (date,book_title,marketplace,amazon_kdp_avg_list_price, amazon_kdp_royalty_type,amazon_kdp_revenue_in_usd, amazon_kdp_royalty_in_usd,amazon_kdp_paid_downloads, amazon_kdp_free_downloads,amazon_ku_pages_read, amazon_ku_revenue_in_usd,create_space_revenue_in_usd, create_space_royalty_in_usd,create_space_paperbacks_sold, daily_total_revenue,daily_total_royalty`) VALUES ('2016-07-16', 'Catalyst Moon: Incursion', 'Amazon.com', 2.99, '70%', 5.98, 4.08, 2, 0, 0, 0.0, 0.0, 0.0, 0, 5.98, 4.08) (ActiveRecord::StatementInvalid)

home / jonsdirewolf / .rbenv / versions / 2.4.0 / lib / ruby​​ / gems / 2.4.0 / gems / mysql2-0.4.9 / lib / mysql2 / client.rb:120:in _query':Mysql2 :: Error:出第1行的列 'amazon_kdp_revenue_in_usd' 范围的值:INSERT INTOrb_amazon_daily(日期,BOOK_TITLE,商场,amazon_kdp_avg_list_price,amazon_kdp_royalty_type,amazon_kdp_revenue_in_usd,amazon_kdp_royalty_in_usd,amazon_kdp_paid_downloads,amazon_kdp_free_downloads,amazon_ku_pages_read,amazon_ku_revenue_in_usd,create_space_revenue_in_usd,create_space_royalty_in_usd,create_space_paperbacks_sold,daily_total_revenue,daily_total_royalty`)VALUES ('2016-07-16','催化剂月亮:入侵','亚马逊',2.99,'70%',5.98,4.08,2,0,0,0.0,0.0,0.0,0,5.98,4.08 )(ActiveRecord :: StatementInvalid)

` What do I do?

“我该怎么办?

1 个解决方案

#1


0  

The thing was in my decimal definition in sql table, I needed to alter my decimal columns likefo example:

事情是我在sql表中的十进制定义,我需要改变我的十进制列像例如:

  `amazon_kdp_revenue_in_usd` decimal(10,5) DEFAULT NULL,

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.7 are as follows:

DECIMAL列的声明语法是DECIMAL(M,D)。 MySQL 5.7中参数的值范围如下:

M is the maximum number of digits (the precision). It has a range of 1 to 65.

M是最大位数(精度)。它的范围是1到65。

D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

D是小数点右边的位数(刻度)。它的范围为0到30,且不得大于M.

(this helped me: Warning#1264:out of range error in mysql)

(这对我有帮助:警告#1264:mysql超出范围错误)

#1


0  

The thing was in my decimal definition in sql table, I needed to alter my decimal columns likefo example:

事情是我在sql表中的十进制定义,我需要改变我的十进制列像例如:

  `amazon_kdp_revenue_in_usd` decimal(10,5) DEFAULT NULL,

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.7 are as follows:

DECIMAL列的声明语法是DECIMAL(M,D)。 MySQL 5.7中参数的值范围如下:

M is the maximum number of digits (the precision). It has a range of 1 to 65.

M是最大位数(精度)。它的范围是1到65。

D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

D是小数点右边的位数(刻度)。它的范围为0到30,且不得大于M.

(this helped me: Warning#1264:out of range error in mysql)

(这对我有帮助:警告#1264:mysql超出范围错误)