2016-05-02 43 views
0

我試圖生成3個支架:錯誤的產生與引用支架

$軌摹支架藝術家姓名:字符串類型:字符串生物:文本簡歷:字符串 網站:字符串

$導軌支架摹標題ArtistSerie:字符串藝術家:引用

$軌摹支架ArtistSeriePhoto照片:字符串 標題:字符串年:整數描述:文本尺寸:字符串 特色:布爾artist_serie:引用

前兩種模式正在創建自己的索引和外鍵正常,但第三個是rake db:migrate後產生這個錯誤:

Mysql2::Error: Key column 'artist_series_id' doesn't exist in table: ALTER TABLE `artist_serie_photos` ADD CONSTRAINT `fk_rails_9422e9e931` 
FOREIGN KEY (`artist_series_id`) 
    REFERENCES `artist_series` (`id`) 

這裏是產生遷移:

class CreateArtists < ActiveRecord::Migration 
    def change 
    create_table :artists do |t| 
     t.string :name 
     t.string :type 
     t.text :bio 
     t.string :resume 
     t.string :site 

     t.timestamps null: false 
    end 
    end 
end 


class CreateArtistSeries < ActiveRecord::Migration 
    def change 
    create_table :artist_series do |t| 
     t.string :title 
     t.references :artist, index: true, foreign_key: true 

     t.timestamps null: false 
    end 
    end 
end 


class CreateArtistSeriePhotos < ActiveRecord::Migration 
    def change 
    create_table :artist_serie_photos do |t| 
     t.string :photo 
     t.string :title 
     t.integer :year 
     t.text :description 
     t.string :dimensions 
     t.boolean :featured 
     t.references :artist_serie, index: true, foreign_key: true 

     t.timestamps null: false 
    end 
    end 
end 

該表已創建並且字段artist_serie_id也是,但索引和外鍵不。

我已經創建了另一個空白項目,它的工作原理(在sqlite上),所以可能是一個MySQL適配器錯誤。

有什麼想法?

我感謝您的幫助!

+1

我想根本問題是'系列'是單數https://en.wikipedia.org/wiki/Series。也就是說,「serie」不是「series」的單數形式。用'sequence'替換'series'可能是值得的。 – ReggieB

+0

是啊!那就是問題所在!!謝謝! –

+0

如果你願意,創建一個答案,我會接受它:) –

回答

1

我預計根本問題是series is singular。也就是說,serie不是series的單數形式。用sequence代替series可能值得。