我刚刚使用rake db:migrate
通过应用程序和数据库进行了更新。但是,我遇到了一个错误:
Migrating to CreateSavedBoards (20110111184104)
== CreateSavedBoards: migrating ==============================================
-- drop_table(:boards)
SQL (0.0ms) Mysql::Error: Unknown table 'boards': DROP TABLE `boards`
rake aborted!
An error has occurred, all later migrations canceled:
Mysql::Error: Unknown table 'boards': DROP TABLE `boards`
(See full trace by running task with --trace)
导致错误的迁移文件?
class CreateBoardCategoriesSavedboards < ActiveRecord::Migration
def self.up
create_table :board_categories_boards, :id => false do |t|
t.integer :board_category_id
t.integer :board_id
end
add_index :board_categories_boards, [:board_category_id, :board_id], :name => "bcb_board_category_id_board_id"
end
def self.down
drop_table :board_categories_boards
end
end
这是委员会的模型。
class Board < ActiveRecord::Base
belongs_to :image, :foreign_key => 'image'
belongs_to :clip, :foreign_key => 'clip'
has_and_belongs_to_many :categories, :class_name => 'BoardCategory', :foreign_key => 'board_id'
has_many :comments, :as => :commentable
set_table_name "savedboards"
end
我认为错误来自Rails认为有一个boards
表,因为上面的迁移文件中有board_id
。
我是否正确地认为这可能导致迁移失败,我该怎么办呢?
答案 0 :(得分:1)
迁移的输出显示drop_table :boards
正在发生,但它不会出现在您的迁移中。也许是早期的迁移试图放弃boards
表?