Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

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

エラーの発生

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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
7
Help us understand the problem. What are the problem?