0
我正在使用rails 4.2 & postgresql和我正在使用現有的非rails數據庫。表架構如下:Postgres主鍵默認值在創建的模型實例中爲零
# == Schema Information
#
# Table name: customer
#
# CustomerNo :text default("P'::text || nextval('sqcustomer_no"), not null, primary key
# CustomerOperatorId :string(8)
# CustomerType :integer
# BrokerId :string(250)
# Address :text
# SalutationId :integer
的問題是:
customer = Customer.create! #successfully created
customer.id #nil value
customer.CustomerNo #nil value
我使用的是2個擴展postgis, plpgsql
和Coutomer.count
增加正常。我試過customer.reload
它給我錯誤。
customer
實例變量
#<Customer CustomerNo: "P'::text || nextval('sqcustomer_no", CustomerOperatorId: nil, CustomerType: nil, BrokerId: nil, Address: nil, SalutationId: nil>
爲什麼我得到這個任何想法的輸出?
感謝 Neelesh
這裏有什麼用? http://stackoverflow.com/questions/5975081/camelcase-instead-of-snake-case-in-rails-db –
@DavidAldridge我做了,但沒有工作。 – Neelesh