简体   繁体   English

rake db:migrate的问题

[英]Issues with rake db:migrate

I am beginner for this Rails . 我是这个Rails的初学者。 I am working hard to fix the following error 我正在努力解决以下错误

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

I manual dropped all the tables that didn't fix the problem Now used rake db:drop db:create db:migrate but still geting rake aborted message.. 我手动删除了所有不能解决问题的表,现在使用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`)

Also i dont have schema.rb file. 我也没有schema.rb文件。

The first message is probably the result of a migration that failed but wasn't properly backed out. 第一条消息可能是迁移失败但未正确撤消的结果。 It's a good idea to take a snapshot of your database before you perform migrations so you can restore to a known-good configuration if it messes up. 在执行迁移之前,最好先对数据库进行快照,以便在混乱时恢复到已知的良好配置。

The second message indicates you're trying to create an index on a field that's "too big" for MySQL to do this. 第二条消息表明您正在尝试在对于MySQL而言“太大”的字段上创建索引。 Due to the way MySQL handles UTF-8 characters, each character is allocated three bytes of key space. 由于MySQL处理UTF-8字符的方式,每个字符分配了三个字节的键空间。 This means anything longer than 255 characters needs to be given a length limit or it won't work, at least in versions of MySQL that complain about it. 这意味着任何长度超过255个字符的字符都需要指定长度限制,否则它将不起作用,至少在抱怨它的MySQL版本中是如此。

What does seem odd is that it's trying to build the schema_migrations table and failing. 似乎很奇怪的是,它正在尝试构建schema_migrations表并失败。 Is there anything unusual about your MySQL configuration that might trigger this? 关于您的MySQL配置,是否有任何异常情况可能会触发此情况? Is it an older version? 它是旧版本吗? 5.5 or better is recommended. 建议5.5或更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM