This project is archived and is in readonly mode.
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
-
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 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 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 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 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.
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>
People watching this ticket
Referenced by
- 1651 Sqlite, sqlite3 bug in add_column when column is primary key (Trac #9385) #1651
- 2080 sqlite missing ddl transactions and savepoints This is related to #1651. The patch should incorporate te...
- 2080 sqlite missing ddl transactions and savepoints Done, fixed #1651 as well.
- 2080 sqlite missing ddl transactions and savepoints Pulled out the savepoint stuff and rebased (and squashed ...