0

I followed the instruction on link below to "create table with no 'id' column", since i am using 'emp_id' instead. Create an ActiveRecord database table with no :id column?

I am facing error "table users has no column named id: CREATE UNIQUE INDEX" from Sqlite. Just wondering if you could provide some suggestions to me. Thank you so much for your kind input.

Below is the original migration file:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users, :id => false do |t|
      t.integer :emp_id
      t.string :name
      t.integer :dept_id
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

Below is the result after running "rake db:migrate"

-- add_index(:users, :id, {:unique=>true})
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table users has no column named id: CREATE UNIQUE INDEX       "index_users_on_id" ON "users" ("id")

Sincerely, Kevin H

Community
  • 1
  • 1
Kevin H
  • 599
  • 1
  • 5
  • 10
  • Looks like your migration is missing something (or you have another migration out there), look at the output -> -- add_index(:users, :id, {:unique=>true}), where is this add_index call happening? – Maurício Linhares Aug 13 '11 at 04:33
  • Hi Mauricio Linhares, you are right. I found out that I have another migration file in the same directory with command "add_index :users, id, :unique => true". When I removed the extra migration file, the problem is solved. Thank you so much for your help! – Kevin H Aug 14 '11 at 02:53

1 Answers1

0

ActiveRecord expects a primary key for all tables that back a model (not a relationship, like a HTBTM–join table). What you're trying to do appears to be STI (single-table inheritance), and it's supported in another fashion (see Single Table Inheritance in The Rails 3 Way).

coreyward
  • 77,547
  • 20
  • 137
  • 166
  • Dear Coreyward, thank you for your feedback. I found out that the root cause is that I got another migration file in the same directory. I have resolved the issue based on suggestion by "Mauricio Linhares". Thank you for your input. You have a wonderful day :) – Kevin H Aug 14 '11 at 02:53