0
在我構建的測試應用程序中將我的一些配置移動到數據庫中的過程中,遇到了一個非常奇怪的問題。每當我嘗試在表中創建新記錄時都會生成錯誤。該錯誤表明SQL查詢因ID列(模型中的DataMapper Serial)爲空而失敗。這個表的模式和用於創建新行的代碼在我所做的更改中未被修改。Ruby DataMapper - 串行列產生空錯誤?
sinatra.error
#<DataObjects::IntegrityError: transactions.id may not be NULL (code: 19, sql state: , query: INSERT INTO "transactions" ("uuid", "oid", "store", "txndatetime", "chargetotal") VALUES ('...', '', '...', '...', '...')
紅寶石語句來創建行:
txn = Transaction.create(:uuid => @uuid, :txndatetime => @timestr, :store => store, :chargetotal => params[:subtotal], :oid => params[:oid])
該表的模型:
class Transaction
include DataMapper::Resource
property :id, Serial
property :uuid, String, :key => true
property :oid, String
property :store, String
property :txndatetime, String
property :status, String
property :refnumber, String
property :chargetotal, String
property :response_hash, String, :length => 255
property :approval_code, String
property :tdate, String
validates_presence_of :uuid, :store
validates_uniqueness_of :uuid
end
發生在我身上。不知道爲什麼。 – tekknolagi 2013-05-02 04:42:41
非常感謝您回答您自己的問題。真的幫助:) – tekknolagi 2013-05-02 04:43:23