Skip to content

Commit b55c85c

Browse files
explicitly delete and recreate required tables
1 parent ebdf753 commit b55c85c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

populate_db.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from faker import Faker
22
from app import app, db
3-
from app.models import Category, Subcategory, Product
3+
from app.models import Category, Subcategory, Product, category_subcategory, subcategory_product
44
import random
55

66

@@ -50,8 +50,17 @@ def create_relationships(categories, subcategories, products, max_category_assoc
5050

5151
def main():
5252
with app.app_context():
53-
db.drop_all()
54-
db.create_all()
53+
category_subcategory.drop(db.engine, checkfirst=True)
54+
subcategory_product.drop(db.engine, checkfirst=True)
55+
Category.__table__.drop(db.engine, checkfirst=True)
56+
Subcategory.__table__.drop(db.engine, checkfirst=True)
57+
Product.__table__.drop(db.engine, checkfirst=True)
58+
59+
Category.__table__.create(db.engine)
60+
Subcategory.__table__.create(db.engine)
61+
Product.__table__.create(db.engine)
62+
category_subcategory.create(db.engine)
63+
subcategory_product.create(db.engine)
5564

5665
categories = create_categories(50)
5766
subcategories = create_subcategories(100)

0 commit comments

Comments
 (0)