0

我正在開發一個Web應用程序與Rails 3.0.9和Postgres 9.4
我想創建has_and_belongs_to_many關聯的連接表,但執行「耙db:migrate「唯一沒有執行遷移的是遷移連接表。 Rails沒有顯示任何錯誤,只是沒有創建表。 當我進行回滾時,rails會顯示一個錯誤,因爲不能刪除表,因爲不存在。遷移has_and_belongs_to_many連接表不創建表

這裏是遷移代碼:

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 

人有一個想法?謝謝!

+0

你嵌套起來的方法中的方法定義。難道這不會真正執行更改方法嗎?因爲它只是該方法的定義,而不是調用它的方法? – jaydel

回答

1

Rails的3.0.x的嘗試:

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嘗試:

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 
+0

我已經試過3.0.x和3.1.X格式,但都沒有工作。我有2個has_and_belongs_to_many關聯的遷移,兩者都有問題。我爲了繼續工作而手動創建表格,這些協會起作用,但遷移沒有奏效。謝謝 – facatalan

+1

你的錯誤是什麼?運行'rake db:migrate --trace' – damienbrz