2013-02-14 179 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或更好的建议。