9

Everything I found about this via searching was either wrong or incomplete in some way. So, how do I:

  • delete everything in my postgresql database
  • delete all my alembic revisions
  • make it so that my database is 100% like new
jthill
  • 55,082
  • 5
  • 77
  • 137
kai
  • 1,288
  • 3
  • 12
  • 24

3 Answers3

4

If you want to do this without dropping your migration files the steps are:

  1. Drop all the tables in the db that are to be recreated.
  2. Truncate the alembic_version table (so it will start from the beginning) - this is where the most recent version is kept.

The you can run:

alembic upgrade head

and everything will be recreated. I ran into this problem when my migrations got in a weird state during development and I wanted to reset alembic. This worked.

C.J. Windisch
  • 191
  • 1
  • 4
3

This works for me:

1) Access your session, in the same way you did session.create_all, do session.drop_all.

2) Delete the migration files generated by alembic.

3) Run session.create_all and initial migration generation again.

1

No idea how to mess with alembic, but for the database, you can just log into the SQL console and use DROP DATABASE foo.

Or were you wanting to clear out all the data, but leave the tables there? If so, Truncating all tables in a postgres database has some good answers.

Xanthir
  • 18,065
  • 2
  • 31
  • 32