13
10

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.

Flask: [root] Error: Can't locate revision identified by 'XXXXXXX' が出てしまい、migrateできないとき。

Last updated at Posted at 2020-03-23

エラーの発生

migration ファイルを消して再度flask db init -> flask db migrateした際、

(flask_env) C:\Users\ryosu\Desktop\sample_2>flask db migrate
C:\Users\ryosu\Anaconda3\envs\flask_env\lib\site-packages\pymysql\cursors.py:170: Warning: (3719, "'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.")
  result = self._query(query)
C:\Users\ryosu\Anaconda3\envs\flask_env\lib\site-packages\pymysql\cursors.py:170: Warning: (1366, "Incorrect string value: '\\x93\\x8C\\x8B\\x9E (...' for column 'VARIABLE_VALUE' at row 1")
  result = self._query(query)
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Can't locate revision identified by 'e7c58547f941

が発生しmigrateできなくなってしまった。

解消方法

mysqlでdbを覗くと、alembic_versionというテーブルが残っていた。

mysql> show tables;
+---------------------+
| Tables_in_sample_db |
+---------------------+
| alembic_version     |
+---------------------+
1 row in set (0.00 sec)

これをdropし、

mysql> drop table alembic_version;
Query OK, 0 rows affected (0.18 sec)

再び、migrateすると無事エラーが解消した。

C:\Users\ryosu\Anaconda3\envs\flask_env\lib\site-packages\pymysql\cursors.py:170: Warning: (1366, "Incorrect string value: '\\x93\\x8C\\x8B\\x9E (...' for column 'VARIABLE_VALUE' at row 1")
  result = self._query(query)
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.autogenerate.compare] Detected added table 'infos'
Generating C:\Users\ryosu\Desktop\sample_2\migrations\versions\3b7a65a2d497_.py ...  done

エラーを検索しても英語の記事しか出てこなかったため、メモとして残しておきます。

13
10
1

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
13
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?