我正在使用:
Rails 3.0.9
MSSQL 2005
我有桌子:
CREATE TABLE [dbo].[edocs](
[id] [int] IDENTITY(1,1) NOT NULL,
[id_claim] [int] NOT NULL,
[id_material] [smallint] NOT NULL,
[is_secondary] [bit] NOT NULL CONSTRAINT [DF_edocs_is_secondary] DEFAULT ((0)),
[title] [varchar](100) COLLATE Ukrainian_CI_AS NOT NULL,
[ext] [varchar](4) COLLATE Ukrainian_CI_AS NOT NULL,
[size] [int] NOT NULL,
[code] [varchar](10) COLLATE Ukrainian_CI_AS NULL,
[receive_date] [datetime] NOT NULL CONSTRAINT [DF_edocs_receive_date] DEFAULT (getdate()),
[reg_date] [datetime] NULL,
[reg_numb] [varchar](10) COLLATE Ukrainian_CI_AS NULL,
[idcead] [int] NULL,
[efile] [int] NULL
)
某些字段具有默认值(例如receive_date
)。
在 Rails 控制器中,我尝试创建新记录:
Edoc.create(
:id_claim => @claim_index,
:id_material => @doc_code,
:title => @file_list.first[:name],
:ext => @file_list.first[:ext],
:size => @file_list.first[:size],
:code => @materials[@doc_code]["code"]
)
但我收到错误消息:
ActiveRecord::StatementInvalid (TinyTds::Error: Cannot insert the value NULL int
o column 'receive_date', table 'eFilling.dbo.edocs'; column does not allow nulls
. INSERT fails.: INSERT INTO [edocs] ([id_claim], [id_material], [is_secondary],
[title], [ext], [size], [code], [receive_date], [reg_date], [reg_numb], [idCEAD
], [eFile]) VALUES (100000, 3, 0, N'text', N'rtf', 80
472, N'al', NULL, NULL, NULL, NULL, NULL)):
但在 MSSQL 2005 控制台中,我可以这样做:
insert into edocs ([id_claim], [id_material],[title], [ext], [size]) values(1, 1, 'rrr', 'rtf', 123)
我不希望 ActiveRecord 通过在我的create方法中添加未指向的字段来自动完成查询。
我怎样才能做到这一点?