0

I am using Ruby on Rails 3 and I would like to change the default primary key for a SQL database table from id to account_id. The account_id statement and behavior should be the same of id (auto-increment, unique, ...).

In my migration file I tryed the following:

create_table :users, :id => false do |t|
  t.integer :account_id
  ...

  t.timestamps
end
add_index :users, :account_id, :primary => true

But using MySQL Workbench, when I try to edit the 'users' table, I get this error:

'users': table is not editable because there is no primary key defined for the table

So, how can I set properly the primary key for my 'users' table?

user502052
  • 14,803
  • 30
  • 109
  • 188

1 Answers1

0

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-create_table

There is a :primary_key option for changing the primary key column

jhlllnd
  • 716
  • 6
  • 10