LoginSignup
3
3

More than 3 years have passed since last update.

[エラー] Golang-migrationを使っていて 「Dirty database version 2. Fix and force version.」が出た時の対処法

Posted at

この記事で説明すること

golang-migrateライブラリを使っていてデータベースのマイグレーションをしたときに

error: Dirty database version 1. Fix and force version.

というエラーが出た時の対処法

環境

  • golang 1.15
  • MySQL

解決法

migrate force コマンドを使う

$ migrate -database 'mysql://root:golang@tcp(mysql:3306)/golang_db?charset=utf8&parseTime=true&loc=Asia%2FTokyo' -path migrations/ ${VERSION}

-database以降はDBのURLを指定
-pathでマイグレーションファイルの場所指定
${VERSION}の部分はエラーで出ているVERSIONを数字で指定。

エラーが起きた原因

テーブルを構成を編集したくて、migrate downコマンドを使った後に、マイグレーションファイルを編集して再度マイグレーションをしようとしたら起きた

3
3
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
3
3