This project is archived and is in readonly mode.

#1651 ✓duplicate
awendt

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

Reported by awendt | December 27th, 2008 @ 10:44 PM | in 2.x

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.

Comments and changes to this ticket

  • Pratik

    Pratik March 12th, 2009 @ 05:27 PM

    • State changed from “new” to “duplicate”
  • JasonKing

    JasonKing March 13th, 2009 @ 11:47 AM

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

  • Nolan Eakins

    Nolan Eakins March 23rd, 2009 @ 04:35 PM

    • 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
    
  • JasonKing

    JasonKing March 23rd, 2009 @ 09:42 PM

    • 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.

  • Nolan Eakins

    Nolan Eakins March 24th, 2009 @ 12:24 AM

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

  • JasonKing

    JasonKing March 24th, 2009 @ 12:46 AM

    • 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.

  • Ryan Bigg

    Ryan Bigg October 9th, 2010 @ 10:12 PM

    • Tag cleared.

    Automatic cleanup of spam.

  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages