1
0

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.

golang-migrateをコード状から動かした時だけエラーになる

Posted at

概要

golang-migrateをコマンドラインで実行した際は特に何も起きないのに、Golangコード上から動かすとエラーが出る。。。

環境

Mysql: 8.0.19

golang-migrate: v4

エラー内容

migration failed in line 0: ALTER TABLE `casts` ADD `secret` VARCHAR(255) DEFAULT '' NOT NULL AFTER `capacity`;
        ALTER TABLE `casts` MODIFY `secret` VARCHAR(255) NOT NULL AFTER `capacity`;
         (details: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE `casts` MODIFY `secret` VARCHAR(255) NOT NULL AFTER `capacity`' at line 2)

実行SQL

ALTER TABLE `casts` ADD `secret` VARCHAR(255) DEFAULT '' NOT NULL AFTER `capacity`;
ALTER TABLE `casts` MODIFY `secret` VARCHAR(255) NOT NULL AFTER `capacity`;

解決法

multiStatements=trueオプションを追加する

user:pass@tcp(host:port)/database?multiStatements=true

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?