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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:43:52+00:00 2026-05-30T03:43:52+00:00

I am using datamapper in a Sinatra application. I currently use the command DataMapper.finalize.auto_upgrade!

  • 0

I am using datamapper in a Sinatra application. I currently use the command

DataMapper.finalize.auto_upgrade!

to handle the migrations. I had two Classes (Artists and Events) with a ‘has_n’ and ‘belongs_to’ association. An Event ‘belonged_to’ one Artist and an Artist could have many Events associated with it.

I changed the association to be a many_to_many relationship by deleting the previous parts of the class definition which governed the original one_to_many association in the models and adding

has n, :artists, :through => Resource

to the Event class and the corresponding code to the Artist class. When I make a new Event, an error is kicked off.

#<DataObjects::IntegrityError: events.artist_id may not be NULL

The :artist_id field is a relic of the original association between the two classes. The new many_to_many association is accessed by event.artists[i] (where ‘i’ is just an integer index going from 0 to the number of associated artists -1). Apparently the original association method between the Artist and Event classes is still there? My guess is the solution to this is to not just use the auto_upgrade method built into datamapper but rather to write an explicit migration. If there is a way to handle this type of change to a database and still have the auto_upgrade method work, that would be great!

If you need more details about my models or anything please ask and I’ll gladly add them.

  • 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-05-30T03:43:54+00:00Added an answer on May 30, 2026 at 3:43 am

    In my experience, DataMapper’s auto_upgrade does not work very well — or, to say the least, it doesn’t work the way I expect it to. If you want to add a new column to your model, it will do what it should; try to do anything more sophisticated to a column and it probably won’t behave as you expect.

    For example, if you create a property of type String, it will initially have a length of 50 characters. If you notice that 50 characters is not enough to hold your string, adding :length => 100 to the model won’t be enough to make auto_upgrade change the column’s width.

    It seems you have stumbled upon another shortcoming, although one may argue that, in your case, maybe DataMapper’s behavior isn’t that bad (think of legacy databases). But the fact is that, when you changed the association, the Event‘s artist_id column wasn’t removed, and then when you try to save an Event, you’ll get an error because the database says it is a required field.

    Notice that the error you are getting is not a validation error: DataMapper thinks everything looks ok, but gets an error from the database when trying to save the object.

    Hope this helps!

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

Sidebar

Related Questions

We are using Datamapper in a Sinatra application and would like to use case
I'm building a small Ruby application using DataMapper and Sinatra, and I'm trying to
I'm creating a very simple timeshare application using Sinatra and Datamapper. Every user in
I am working on a simple budget app using Sinatra and DataMapper in Ruby.
I have a problem with DataMapper (I'm using it with Sinatra) I have a
Using the following classes and their associations. class Repository include DataMapper::Resource property :id, Serial
I am trying to call a select statement using datamapper in sinatra. here is
I tried to uninstall datamapper using the command gem uninstall dm-core . But it
I use datamapper and postgres for my ror application, in my models i have
I'm using Sinatra, EventMachine, DataMapper, SQLite3 and the Twitter Stream API to capture and

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.