facatalan
facatalan

Reputation: 1

Migration a has_and_belongs_to_many join table don't create the table

I'm develop a web app with Rails 3.0.9 and Postgres 9.4
I'm trying to create a join table for a has_and_belongs_to_many association, but when execute "rake db:migrate" the only one not executed migration is the migration for join table. Rails didn't show any error, only didn't create the table. When I do the rollback, rails show a error because couldn't drop the table because don't exist.

Here is the code of migration:

class CreateCampanaLocalJoinTable < ActiveRecord::Migration
  def self.up
    def change
      create_table :campanas_locals, :id => false do |t|
        t.integer :campana_id
        t.integer :local_id
      end
    end
  end

  def self.down
    drop_table :campanas_locals
  end
end

Anyone have an idea? Thanks!

Upvotes: 0

Views: 835

Answers (1)

damienbrz
damienbrz

Reputation: 1806

Rails 3.0.X try:

class CreateCampanaLocalJoinTable < ActiveRecord::Migration
  def self.up
    create_table :campanas_locals, :id => false do |t|
      t.integer :campana_id
      t.integer :local_id
    end
  end

  def self.down
    drop_table :campanas_locals
  end
end

Rails 3.1.X try:

class CreateCampanaLocalJoinTable < ActiveRecord::Migration
  def change
    create_table :campanas_locals, :id => false do |t|
      t.integer :campana_id
      t.integer :local_id
    end
  end
end

Upvotes: 1

Related Questions