Flask not creating migrations in Heroku app #468
Replies: 11 comments
-
Did you notice this message?
This is saying that one of your migration scripts (the one with id |
Beta Was this translation helpful? Give feedback.
-
Thank you for the reply. I did notice that. But I don't understand why that is happening. In Heroku PostgreSQL I manually updated my
Currently the existing tables in the database are:
So of course I get the warning that
A bit more background on the issue. On my local Sqlite I made some mistakes when creating the Previous migration script I deleted all the old migrations scripts prior to the previous one so there might be a disconnect between the last successfully applied migration script and the previous migration script. Previous Migration Script
Latest Migration Script
|
Beta Was this translation helpful? Give feedback.
-
Let me remove the parts of the error message that aren't interesting, so that you see more clearly what's happenning:
Alembic is saying you don't have this migration script, even though it is referenced in the other migration. |
Beta Was this translation helpful? Give feedback.
-
I deleted all the old migrations scripts prior to the previous one so there might be a disconnect between the last successfully applied migration script and the previous migration script. ""Alembic is saying you don't have this migration script, even though it is referenced in the other migration."" Okay thanks. So how do I fix this? I don't have the scripts anymore. Also, I'm telling alembic to focus on '484a60f779cd' which points to down revision 'f90467badb79' which does exist. |
Beta Was this translation helpful? Give feedback.
-
I can't give you the specific instructions because I don't know what you have and what you deleted, but what I can tell you is that the migration history needs to be a continuous chain, where each migration links to the previous one. You may need to rebuild the chain with what you have left, or start over from scratch. |
Beta Was this translation helpful? Give feedback.
-
By start over from scratch you mean delete my /migrations folder and rerun |
Beta Was this translation helpful? Give feedback.
-
I mean delete your migrations, delete all your tables in your database (including alembic_version), and then start over by running the |
Beta Was this translation helpful? Give feedback.
-
I fixed the issue. Just for future reference, you don't need to delete everything and drop all tables in the database. But you do need to start over as you said with a migration script whose down revision points to I did the following locally: (1) Deleted
Finally I pushed to my Github repo: |
Beta Was this translation helpful? Give feedback.
-
This is not a great fix, because your migration repository only has this last migration that you needed. Now you have no record of all the previous tables that you have in your database. The solution I proposed would have included all the other tables in your migration as well. If you ever need to generate a new database, such as when you have a new teammate, or if you decide to migrate your deployment to another platform, then you will have a hard time recreating your database from the migration repository. |
Beta Was this translation helpful? Give feedback.
-
This is still in development so it doesn't matter. When I go live I will be starting from the beginning anyway. But you are right generally speaking. |
Beta Was this translation helpful? Give feedback.
-
You could have backed up your data, then restore it once you have a complete migration repository. Or switch to a dummy empty database to create the migration repository, then go back to your real database once the migration script was generated. These are all better options that will allow you to regenerate your database if you need to in the future. |
Beta Was this translation helpful? Give feedback.
-
I made some new migrations in my local database. Then I pushed to Github. Then fired up my Heroku PostgreSQL terminal but I can't create a migration on it.
Before I pushe to Github, I did delete some old migrations and fiddled around in my local branch.
Beta Was this translation helpful? Give feedback.
All reactions