Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Sqlite, sqlite3 bug in add_column when column is primary key (Trac #9385)

#1651

This is merely a follow-up for http://dev.rubyonrails.org/ticke..., a ticket filed one year ago. It never got commented.

I just bumped into this as well. Initial problem: I didn't have an id column for primary key in one of my tables. I didn't run into problems with 2.0.2

2.2.2 suddenly introduces a requirement for an id column in validates_uniqueness_of (which itself should be considered a bug, but is of no concern here). So I wrote a migration that gives me

SQLite3::SQLException: Cannot add a PRIMARY KEY column: ALTER TABLE "responses" ADD "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL

The code for 2.0.2 is on http://github.com/awendt/hyggelig, I could push the 2.2.2 code on a branch.

Reported by awendt · December 27th, 2008 @ 10:44 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Pratik
  2. JasonKing
    JasonKing

    I suspect that Pratik meant to put the ticket #2080 sqlite missing ddl transactions and savepoints in his comment. I've included the fix for this in my patch for a related issue - just took your tests directly.

    March 13th, 2009 @ 11:47 AM

  3. Nolan Eakins
    Nolan Eakins
    • Assigned user set to Pratik

    Wish I could reopen this bug, but w/ Rails 2.3 I am unable to add a primary key column using sqlite3. The following is the error I received while migrating:

    ==  AddIdToEmployees: migrating ===========================
    -- add_column(:employees, :id, :primary_key)
    rake aborted!
    An error has occurred, all later migrations canceled:
    
    SQLite3::SQLException: Cannot add a PRIMARY KEY column: ALTER TABLE "employees" ADD "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
    

    March 23rd, 2009 @ 04:35 PM

  4. JasonKing
    JasonKing
    • Tag changed from 2.2.2, database, migrations, refactoring, sql, sqlite3 to 2.2.2, database, migrations, primary_key, refactoring, sql, sqlite3

    Which version of rails are you using? In 2.3.2 the adapter doesn't even use the ALTER TABLE statement for adding primary key columns - so you're not using the final 2.3 release.

    March 23rd, 2009 @ 09:42 PM

  5. Nolan Eakins
    Nolan Eakins

    I'll give 2.3 a try. This will be another reason to upgrade talk my client into upgrading to Rails 2.3.

    March 24th, 2009 @ 12:24 AM

  6. JasonKing
    JasonKing
    • Assigned user cleared.

    Your original comment said that you were using 2.3 :) I guess you're using 2.2 - so yeah, this bug was fixed in the 2.3 final release (v2.3.2).

    Before this, in sqlite, there's no way to add a primary key column with a Rails migration because of the sqlite limitations in ALTER TABLE.

    March 24th, 2009 @ 12:46 AM

  7. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:12 PM

  8. bingbing