简体   繁体   中英

Issues with rake db:migrate

I am beginner for this 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..

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.

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. Due to the way MySQL handles UTF-8 characters, each character is allocated three bytes of key space. 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.

What does seem odd is that it's trying to build the schema_migrations table and failing. Is there anything unusual about your MySQL configuration that might trigger this? Is it an older version? 5.5 or better is recommended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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