簡體   English   中英

rake db:migrate的問題

[英]Issues with rake db:migrate

我是這個Rails的初學者。 我正在努力解決以下錯誤

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但仍然收到rake中止的消息。

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文件。

第一條消息可能是遷移失敗但未正確撤消的結果。 在執行遷移之前,最好先對數據庫進行快照,以便在混亂時恢復到已知的良好配置。

第二條消息表明您正在嘗試在對於MySQL而言“太大”的字段上創建索引。 由於MySQL處理UTF-8字符的方式,每個字符分配了三個字節的鍵空間。 這意味着任何長度超過255個字符的字符都需要指定長度限制,否則它將不起作用,至少在抱怨它的MySQL版本中是如此。

似乎很奇怪的是,它正在嘗試構建schema_migrations表並失敗。 關於您的MySQL配置,是否有任何異常情況可能會觸發此情況? 它是舊版本嗎? 建議5.5或更高。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM