alembic util command error can't find identifier

前端 未结 3 463
死守一世寂寞
死守一世寂寞 2021-01-30 06:51

I\'m trying to use alembic to handle local migrations on my project. It worked the first time, but then I needed to delete the folder and restart.(don\'t ask why, I just had to)

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 07:11

    SirKaiserKai's solution didn't work for me, likely because I made some stupid mistake last time I migrated and deleted a file that I should have kept.

    Instead of dropping the alembic_revision table I just updated the value in version_num to match where I knew my DB was at.

    Make sure you use the migration ID of the file that matches the current state of your database

    1. Check the missing migration number

      psql=> SELECT * FROM alembic_version;
      +-------------------------+
      |      version_num        |
      +-------------------------+
      |  |
      +-------------------------+
      (1 row)
      
    2. Update the value

      psql=> UPDATE alembic_version
      psql->    SET version_num = ''
      psql->    WHERE version_num = '';
      UPDATE 1
      

    If your database is in a state other than the migration file then you're just going to continue to have errors. However, you could run a alembic upgrade head if the is a migration file continuing from where you left off previously, and that would run all the migrations post this state as well.

提交回复
热议问题