Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5644 (new defect)

Opened 2 years ago

Last modified 2 years ago

no way to drop primary key

Reported by: srjoseph@hawaii.edu Assigned to: David
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: 1.1.1
Severity: normal Keywords: drop :primary_key
Cc: bitsweat

Description

During migration it does not appear possible to drop or add primary keys (for MySQL at least). The current list of schema statements in ActiveRecord::ConnectionAdapters::SchemaStatements includes remove_index and add_index, but they cannot currently be used to add or remove primary key status.

I have resolved this problem for MySQL by using MySQL specific statements:

ActiveRecord::Base.connection.insert('ALTER TABLE workspaces_discussions DROP PRIMARY KEY')

Clearly not ideal, but there is no other option at this point.

One other note is that when migration fails they should roll back the changes they made so far, otherwise you get stuck with a db in an intermediate state

Change History

07/07/06 22:18:24 changed by bitsweat

  • cc set to bitsweat.
  • version set to 1.1.1.
  • milestone set to 1.x.

Please do look into primary_key operations for migrations.

(Many databases, including MySQL, don't support transactions DDL statements.)