Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:34:13+00:00 2026-06-03T10:34:13+00:00

I am using: Rails 3.0.9 MSSQL 2005 I have the table: CREATE TABLE [dbo].[edocs](

  • 0

I am using:
Rails 3.0.9
MSSQL 2005

I have the table:

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

)

Some of fields has default value (for exapmle receive_date).
In Rails controller I try to create new record:

    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"]
    )

But I get error message:

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)):

But In MSSQL 2005 console I can do that:

insert into edocs ([id_claim], [id_material],[title], [ext], [size]) values(1, 1, 'rrr', 'rtf', 123)

I don’t want ActiveRecord auto completes the query by adding fields are not pointed in my create method.

How Can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:34:15+00:00Added an answer on June 3, 2026 at 10:34 am

    I believe that even if you wrote straight SQL queries to insert, and didn’t specify values for the “not null” fields, and they didn’t have a default value, you would still throw a SQL error. I would suggest either allowing NULL on those fields or giving them a default value (maybe ” or 0?).

    This isn’t just a Rails thing, this comes down to the SQL queries themselves.

    Example, for table with ‘id’, ’email’ and ‘name’, where ‘name’ is not null and has no default value, this would fail:

    INSERT INTO table (id, email) VALUES ('3', 'test@example.com')

    As SQL passes NULL or emptiness as the value to ‘name’

    Think of it kind of like a ‘required field’ when it is not null without default value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using: Rails 3.0.9 Activerecord-sqlserver-adapter 3.0.15 TinyTds MSSQL 2005 I have following table: CREATE
I have been using MSSQL 2005 with Rails for quite a while now, and
Using: Rails 3.0.3 Friendly_id: 4.0.0.beta11 I have create a fully working development version of
I am using MSSQL 2005. I have StringIO object that contains my zip file
I'm using Rails 3 with a MySQL database, and I need to programmatically create
I have a deployment using: rails 2.3.2 ruby 1.8.7 mysql db and 3 mongrel
Using Rails 3.1.3 with Ruby 1.9.3p0. I've discovered that by default, Rails does not
I'm using rails 3.0 and MySql 5.1 I have these three models: Question, Tag
I wanted to create an online shop using rails and the spree gem (http://spreecommerce.com/).
I have a problem with relations while using sqlite3 on rails. First i build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.