Let's say I create a table in a Rails migration, specifying to omit the identifier column:
create_table :categories_posts, :id => false do |t| t.column :category_id, :integer, :null => false t.column :post_id, :integer, :null => false end
Later, I decided that I wanted to add an identifier column as a primary key in order to create a new migration:
class ChangeCategoriesToRichJoin < ActiveRecord::Migration def self.up add_column :categories_posts, :id, :primary_key end def self.down remove_column :categories_posts, :id end end
But when I look at the table after migration, it looks like this:
category_id post_id id
The id column is at the last position in the table, whereas usually the id column will be the first.
Is there a way to change the ChangeCategoriesToRichJoin migration to insist on creating an id column before the category_id column in the table?
Or do I need to drop the table and add a column to the definition of "create table"?
ruby-on-rails migration
pez_dispenser
source share