Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 ActiveRecord inserting autoincrement field issue
    primarykey
    data
    text
    <p>I'm using:<br> <strong>Rails 3.0.9<br> Activerecord-sqlserver-adapter 3.0.15<br> TinyTds<br> MSSQL 2005</strong> </p> <p>I have following table: </p> <pre><code>CREATE TABLE [dbo].[eclaims]( [id_app] [int] IDENTITY(1,1) NOT NULL, [id_user] [int] NOT NULL, [property] [varchar](4) NOT NULL, [app_number] [varchar](15) NULL, [patent_number] [varchar](15) NULL, [native_number] [varchar](20) NULL, [title] [nvarchar](max) NULL, [applicants] [nvarchar](max) NULL, [receive_date] [datetime] NULL, [change_date] [datetime] NOT NULL CONSTRAINT [DF_eclaims_change_date] DEFAULT (getdate()), CONSTRAINT [PK_eclaims] PRIMARY KEY CLUSTERED ( [id_app] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[eclaims] WITH CHECK ADD CONSTRAINT [FK_eclaims_users] FOREIGN KEY([id_user]) REFERENCES [dbo].[users] ([id]) GO ALTER TABLE [dbo].[eclaims] CHECK CONSTRAINT [FK_eclaims_users] </code></pre> <p>The model is: </p> <pre><code># coding: utf-8 class Eclaim &lt; ActiveRecord::Base end </code></pre> <p>As you can see there is auto-increment field named id_app.<br> When I try execute a query <code>insert into eclaims (id_user, [property], title) values (1, 2, 'Alex')</code> in MSSQL console everything goes perfect. </p> <p>But when I try <code>Eclaim.create(:id_user =&gt; 1, :property =&gt; 'inv', :change_date =&gt; Time.now )</code> </p> <p>I am getting such error <strong><code>TinyTds::Error: DEFAULT or NULL are not allowed as explicit identity values.: INSERT INTO [eclaims] ([id_app], [id_user], [property], [app_number], [patent_number], [native_number], [title], [applicants], [receive_date], [change_date]) VALUES (NULL, 1, N'inv', NULL, NULL, NULL, NULL, NULL, NULL, '2012-05-08 06:39:14.882')</code></strong></p> <p>Why ActiverRecord doesn't insert the auto-increment field <strong>id_app</strong> automatically?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload