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