2016-10-17 81 views
0
create_table :offers do |t| 
    t.numeric(15,2) :total_sales 
    t.numeric(10,2) :price 
    t.numeric(10,2) :discount 
end 

我收到此錯誤如何使規模和精度的數值數據類型在創建表

create_offers.rb:12: syntax error, unexpected ':', expecting keyword_end 
     t.numeric(15,2) :total_sales 
        ^
/home/gvpmahesh/code/present-app/present/db/migrate/20161017072207_create_offers.rb:13: syntax error, unexpected ':', expecting keyword_end 
     t.numeric(10,2) :price 
        ^
/home/gvpmahesh/code/present-app/present/db/migrate/20161017072207_create_offers.rb:14: syntax error, unexpected ':', expecting keyword_end 
     t.numeric(10,2) :discount 
        ^

回答

1

你想使用十進制類型來存儲財務數據:

create_table :offers do |t| 
    t.decimal :total_sales, precision: 15, scale: 2 
    t.decimal :price,  precision: 10, scale: 2 
    t.decimal :discount, precision: 10, scale: 2 
end 

結賬official guides on migrations

1
create_table :offers do |t| 
    t.decimal :total_sales, precision: 15, scale: 2 
    t.decimal :price, precision: 10, scale: 2 
    t.decimal :discount, precision: 10, scale: 2 
end 
相關問題