0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MySQLに変更してdb:migrateするとエラーになる。

Posted at

#概要
RailsアプリでMySQLに変更してdb:createは無事完了。
続いてdb:migrateするとエラーになってしまう。

Mysql2::Error: Can't DROP 'uid'; check that column/key exists
ActiveRecord::StatementInvalid: Mysql2::Error: Can't DROP 'uid'; check that column/key exists

#原因
不要なマイグレーションファイルが原因。

bundle exec rake db:migrate:status #マイグレーションファイルのステータスを確認。
   up     20201201080551  Devise create users
   up     20201204060220  Create microposts
   up     20201221072358  Add column microposts
  down    20201222055950  Remove from users
  down    20201222065441  Remove uid from users
  down    20201222065731  Remove provider from users
  down    20201222065821  Remove username from users
  down    20201222155423  Add column to users

#解決策
ステータスがdownになっているマイグレーションファイルを削除

rm -rf db/migrate/20201222055950_remove_from_users.rb 
rm -rf db/migrate/20201222065441_remove_uid_from_users.rb 
rm -rf db/migrate/20201222065731_remove_provider_from_users.rb 
rm -rf db/migrate/20201222065821_remove_username_from_users.rb 
rm -rf db/migrate/20201222155423_add_column_to_users.rb 

MySQLを再起動

sudo mysql.server restart
rails db:migrate
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?