Forums

Migration failed when entering a new table

Hi team, I am finishing the tutorial https://blog.pythonanywhere.com/158/ everything is fine except for the migrations that did not accept the users database that we included at the end of the tutorial, because when launching the script "flask db migrate" it did not recognize any changes. When consulting the tables in the MySQL console, the users table does not appear, only the comments table appears:

(flask-tutorial) 09:26 ~ / mysite (master) $ flask db migrate

INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. ERROR [flask_migrate] Error: Can't locate revision identified by '050a1f903898'

(flask-tutorial) 09:38 ~ / mysite (master) $ flask db upgrade

INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. ERROR [flask_migrate] Error: Can't locate revision identified by '050a1f903898'

I will appreciate any guidance :)

It sounds like you have broken your migrations in some way. The easiest way to recover from that (since you've just completed the tutorial) would be to delete your existing database and re-create it from scratch.

The golden rule that restarting works again! I lost this point, but now I have everything working perfectly again, thanks for redirecting me :)

@pysoft Glad to hear that it works for you!

[edited by admin]

(flask-tutorial) 02:11 ~/mysite (master)$ flask db migrate
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [flask_migrate] Error: Can't locate revision identified by 'ec8a9ab86b71'
(flask-tutorial) 02:12 ~/mysite (master)$ flask db init
Error: Directory migrations already exists and is not empty
(flask-tutorial) 02:14 ~/mysite (master)$ flask db history 
<base> -> ffde00e83b1b (head), empty message
(flask-tutorial) 02:16 ~/mysite (master)$ alembic revisions
usage: alembic [-h] [--version] [-c CONFIG] [-n NAME] [-x X] [--raiseerr] [-q]
               {branches,check,current,downgrade,edit,ensure_version,heads,history,init,list_templates,merge,revision,show,stamp,upgrade}
               ...
alembic: error: invalid choice: 'revisions' (choose from 'branches', 'check', 'current', 'downgrade', 'edit', 'ensure_version', 'heads', 'history', 'init', 'list_t
emplates', 'merge', 'revision', 'show', 'stamp', 'upgrade')
(flask-tutorial) 02:18 ~/mysite (master)$ alembic revision --message "Recreate missing migration ec8a9ab86b71"
  FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section
(flask-tutorial) 02:19 ~/mysite (master)$ alembic upgrade head
  FAILED: No config file 'alembic.ini' found, or file has no '[alembic]' section
(flask-tutorial) 02:20 ~/mysite (master)$ alembic init
usage: alembic init [-h] [-t TEMPLATE] [--package] directory
alembic init: error: the following arguments are required: directory
(flask-tutorial) 02:20 ~/mysite (master)$  flask db upgrade
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [flask_migrate] Error: Can't locate revision identified by 'ec8a9ab86b71'

how to solve this error

I do not know the state of your project but you will find some general help here.