1

I have a table in SQL Server set up with a default value for a uniqueidentifier not null.

I do not want ActiveRecord to send the null value to the database, but it is, causing a 'Cannot insert null value into not null column' error.

How do I save an ActiveRecord without sending columns that have defaults? I don't really want to:

  1. Making the columns nullable.
  2. Using Rails to generate the GUID and sending it to the database
  3. Writing the query manually.

I could do either 2 or 3 this seems like something that has to be doable in plain ActiveRecord/RoR.

1 Answer 1

0

Unfortunately I think this is an issue with Rails with Sql Server as using Rails with MySql handles defaults (and this situation) correctly. There may be other options, but probably the quickest is to add a before_create callback to your ActiveRecord class and set the guid there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.