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 7822101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:49:47+00:00 2026-06-02T07:49:47+00:00

class User include DataMapper::Resource property :id, Serial property :name, String property :email, String has

  • 0
class User

    include DataMapper::Resource

    property :id,              Serial
    property :name,            String
    property :email,           String

    has n, :records

end


class Project
    include DataMapper::Resource

    property :id,          Serial
    property :name,        String

    has n, :records ?????

end
#
class Record

   # SPEND_REGEX = /^[0-9]{1}:[0-5]{1}[0-9]{1}$/

    include DataMapper::Resource


    property :id,                Serial
    property :reporting_type,    String
    property :spend_time,        String

    belongs_to :user
    belongs_to :project ????


end

  DataMapper.auto_upgrade!

With ??? I marked relation that throws an error “`execute_non_query’: Cannot add a NOT NULL column with default value NULL (DataObjects::SyntaxError)
”
How to define 2 has many relationships to one model in datamapper?

  • 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-02T07:49:48+00:00Added an answer on June 2, 2026 at 7:49 am

    By default, your belongs_to relationships are required. I assume you already have Record entries in your database. The auto_upgrade is trying to add the new field for the association, and by default it marks that column as NOT NULL. However, for all the existing records, that value will be NULL.

    To get around this, do one of the following:

    • Do an auto_migrate instead of auto_upgrade. This will blow away your data, but
      will allow you to add the relationship columns without it choking on
      NULL values.
    • Make the associations optional with :required => false. This will allow NULLs in the database. Next, go in and set those fields to the appropriate values. Lastly, modify the database table column to be NOT NULL.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this model class User include DataMapper::Resource include BCrypt property :id, Serial property
In my model I have class Alias include DataMapper::Resource belongs_to :user property :id, String,
Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
I work with Sinatra. This is my models. class Post include DataMapper::Resource property :id,
Here's my irb session: irb(main):001:0> class User irb(main):002:1> include MongoMapper::Document irb(main):003:1> key :name, String
I have following code class User attr_accessor :name end u = User.new u.name =
OK, just got: class User include Mongoid::Document # devise stuff... has_one :card end class
I have some class CurrentUser class CurrentUser < User include Singleton end User is
Let’s say you have the following mongoid documents: class User include Mongoid::Document embeds_one :name
Models: class User include Mongoid::Document embeds_many :user_topics end class UserTopic include Mongoid::Document embedded_in :user

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.