2013-02-14 208 views
0

我是這個Rails的初學者。我正在努力 解決以下錯誤Rake db問題:遷移

C:\library>rake db:migrate --trace 
(in C:/library) 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Execute db:migrate 
== CreateBooks: migrating 
==================================================== 
-- create_table(:books) 
rake aborted! 
An error has occurred, all later migrations canceled: 

Mysql::Error: Table 'books' already exists: CREATE TABLE `books` (`id` 
int(11) D 
EFAULT NULL auto_increment PRIMARY KEY, `created_at` datetime, 
`updated_at` date 
time) ENGINE=InnoDB 

我手動下降沒有解決問題的所有表 現在使用rake db:drop db:create db:migrate但仍歌廳耙 中止的消息..

C:\library>rake db:drop db:create db:migrate 

(in C:/library) 
rake aborted! 
Mysql::Error: Specified key was too long; max key length is 767 bytes: 
CREATE UN 
IQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`) 

另外我沒有schema.rb文件。

回答

1

第一條消息可能是遷移失敗但未正確退出的結果。在執行遷移之前創建數據庫快照是一個好主意,這樣如果它發生混亂,您可以恢復到已知好的配置。

第二條消息表明您正試圖在「太大」的字段上創建索引,以便MySQL執行此操作。由於MySQL處理UTF-8字符的方式,每個字符被分配了三個字節的密鑰空間。這意味着超過255個字符的任何內容都需要被賦予一個長度限制,或者至少在抱怨它的MySQL版本中不起作用。

看起來很奇怪的是,它試圖構建schema_migrations表並失敗。關於你的MySQL配置有什麼不尋常的事情可能觸發這種情況?它是舊版本嗎? 5.5或更好的建議。