【Rails】マイグレーション実行時エラー Mysql2::Error: Table 'infos' already exists: CREATE TABLE…
scaffoldやってマイグレーション実行したらエラーが。
$ rails g scaffold info article:text
$ rake db:migrate
== 20181005153006 CreateInfos: migrating ======================================
-- create_table(:infos)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:Mysql2::Error: Table 'infos' already exists: CREATE TABLE `infos` (`id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, `article` text, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL)
Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'infos' already exists: CREATE TABLE `infos` (`id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, `article` text, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL)Caused by:
Mysql2::Error: Table 'infos' already exists
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
(ディレクトリなど省略)
ググるとこういう時はDBを作り直すのがよいとのことで。
$ rake db:drop
$ rake db:create
$ rake db:migrate
無事できました。
<参考>