Krzysztof Żuraw
Krzysztof Żuraw

Reputation: 107

Flask Sql-alchemy not dropping tables created by alembic

I have flask application with Flask-migrate. Running db upgrade creates following tables:

              List of relations
Schema |      Name       | Type  |  Owner   
-------+-----------------+-------+----------
public | alembic_version | table | postgres
public | operations      | table | postgres
public | rule_values     | table | postgres
public | rules           | table | postgres
public | shares          | table | postgres

But when I drop all tables with:

db = SQLAlchemy(app)
db.drop_all()

I got this:

              List of relations
Schema |      Name       | Type  |  Owner   
-------+-----------------+-------+----------
public | alembic_version | table | postgres

Is there solution to drop all tables (even alembic_version)?

Upvotes: 3

Views: 2651

Answers (2)

Krzysztof Żuraw
Krzysztof Żuraw

Reputation: 107

I found answer- it is not to drop database but to downgrade it to base migration via:

db downgrade base

Upvotes: 1

bakkal
bakkal

Reputation: 55448

I want to start from empty database

In that case do it at the database level (as opposed to the application level), e.g. delete the .db file for SQLite, DROP DATABASE for PostgreSQL etc.

You could make a script to drop and then recreate the DB (and run the migrations on it) if you do this often.

Because on the application level, the DB management software will want to keep some information to track the schema versions.

Upvotes: 1

Related Questions