Help me create primary_key with ActiveRecord::Migration

I have two tables books and categories. I create a join table books_categories. Now how to create couple primary key(book_id,category_id)

class BooksCategories < ActiveRecord::Migration   def self.up      create_table :books_categories,:id => false do |t|         t.integer :book_id         t.integer :category_id      end   end .............. end

Tuan Minh wrote:

I have two tables books and categories. I create a join table books_categories. Now how to create couple primary key(book_id,category_id)

class BooksCategories < ActiveRecord::Migration   def self.up      create_table :books_categories,:id => false do |t|         t.integer :book_id         t.integer :category_id      end   end .............. end

I believe by default rails will create a primary key for you

You are removing your “primary key” with the :id => false

It’s not technically a “primary key” but by default ActiveRecord will look at that column.

Hope that helps some.

Bryan Ray wrote:

It's not technically a "primary key" but by default ActiveRecord will look at that column.

Actually: