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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:28:32+00:00 2026-05-15T18:28:32+00:00

I am getting the following error while trying to add a NOT NULL column

  • 0

I am getting the following error while trying to add a NOT NULL column to an existing table. Why is it happening ?. I tried rake db:reset thinking that the existing records are the problem, but even after resetting the DB, the problem persists. Can you please help me figure this out.

Migration File

class AddDivisionIdToProfile < ActiveRecord::Migration
  def self.up
    add_column :profiles, :division_id, :integer, :null => false
  end

  def self.down
    remove_column :profiles, :division_id
  end
end

Error Message

SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL: ALTER TABLE “profiles” ADD “division_id” integer NOT NULL

  • 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-15T18:28:33+00:00Added an answer on May 15, 2026 at 6:28 pm

    You already have rows in the table, and you’re adding a new column division_id. It needs something in that new column in each of the existing rows.

    SQLite would typically choose NULL, but you’ve specified it can’t be NULL, so what should it be? It has no way of knowing.

    See:

    • Adding a Non-null Column with no Default Value in a Rails Migration (2009, no longer available, so this is a snapshot at archive.org)
    • Adding a NOT NULL Column to an Existing Table (2014)

    That blog’s recommendation is to add the column without the not null constraint, and it’ll be added with NULL in every row. Then you can fill in values in the division_id and then use change_column to add the not null constraint.

    See the blogs I linked to for an description of a migration script that does this three-step process.

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

Sidebar

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can create a separate project that contains WCF Ria… May 16, 2026 at 10:48 am
  • Editorial Team
    Editorial Team added an answer You can use an expression as an additional field in… May 16, 2026 at 10:48 am
  • Editorial Team
    Editorial Team added an answer First : You did everything right You can use mysql_fetch_assoc… May 16, 2026 at 10:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

All of a sudden I start getting this error while trying to open 2
I'm getting this error (see title) while trying to parse an XML file in
I am getting the following error while obfuscating my application. How can i define
I'm getting the following error when I connect my Silverlight app to my WCF
I'm getting the following error on my site; Microsoft VBScript compilation error '800a03f2' Expected
I am getting the following error after deploying my web application to a 2008
I am getting the following error: Cannot implicitly convert type IValueProvider to IDictionary When
I am trying to merge records from an Oracle database table to my local
I am trying to debug my Windows Phone 7 app, and I am getting
I've been trying for about a day to get a table cell to display

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.