在ROR中創建關聯表失敗了(數據庫用的是sqlite3)

(沒有積分,因此沒辦法在問答頻道問問題.路過的,幫忙解答下)

我首先用的是

引用
script/generate migration create_books_and_authors



  然后在編輯器中打開了對應的rb文件,代碼如下:

class CreateBooksAndAuthorsBooks  255, :null=> false

      table.column :publisher_id, :integer, :null=> false

      table.column :published_at, :datetime

      table.column :isbn, :string, :limit=>13, :unique=> true

      table.column :blurb, :text

      table.column :page_count, :integer

      table.column :price, :float

      table.column :created_at, :timestamp

      table.column :updated_at, :timestamp

    end

    create_table :authors_books, :id => false do |table|

      table.column :author_id, :integer, :null=> false

      table.column :book_id, :integer, :null=> false

    end

   

    say_with_time  'Adding foreign keys'  do

     

      execute 'ALTER TABLE authors_books ADD CONSTRAINT fk_bk_authors FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE'

     

      execute 'ALTER TABLE authors_books ADD CONSTRAINT fk_bk_books FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE'

     

      execute 'ALTER TABLE books ADD CONSTRAINT fk_books_publishers FOREIGN KEY (publisher_id) REFERENCES publishers(id) ON DELETE CASCADE'

  end

end

    

   

  def self.down

    drop_table :authors_books

    drop_table :books

  end

end






然后執行

引用
rake db:migrate


引用
== 3 CreateBooksAndAuthorsBooks: migrating ====================================

-- create_table(:books)

rake aborted!

SQLite3::SQLException: table books already exists: CREATE TABLE books ("id" INTE

GER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "publishe

r_id" integer NOT NULL, "published_at" datetime DEFAULT NULL, "isbn" varchar(13)

DEFAULT NULL, "blurb" text DEFAULT NULL, "page_count" integer DEFAULT NULL, "pr

ice" float DEFAULT NULL, "created_at" datetime DEFAULT NULL, "updated_at" dateti

me DEFAULT NULL)



卻發現只創建了books表,而authors_books表并未創建.

請問是否是代碼錯了,或者是其它什么原因呢?

 

你可能感兴趣的:(oracle,Ruby,Rails)