husseinelsaadi commited on
Commit
f3a3e9b
·
1 Parent(s): 10ccff6
backend/models/database.py CHANGED
@@ -51,17 +51,18 @@ class Application(db.Model):
51
  except:
52
  return {}
53
 
 
54
  def init_db(app):
55
  """Initialize the database with the Flask app."""
56
  db.init_app(app)
57
 
58
- # Import all models before db.create_all()
59
- import backend.models.user # <-- Don't just import User directly
60
- import backend.models.database # Your Job and Application classes are here
61
-
62
  with app.app_context():
 
 
 
63
  db.create_all()
64
 
 
65
  if Job.query.count() == 0:
66
  sample_jobs = [
67
  Job(
@@ -87,6 +88,8 @@ def init_db(app):
87
  ),
88
  ]
89
 
90
- db.session.add_all(sample_jobs)
 
 
91
  db.session.commit()
92
- print("Sample jobs added to database.")
 
51
  except:
52
  return {}
53
 
54
+ # Initialize the database
55
  def init_db(app):
56
  """Initialize the database with the Flask app."""
57
  db.init_app(app)
58
 
 
 
 
 
59
  with app.app_context():
60
+ # ✅ IMPORT ALL MODELS BEFORE db.create_all()
61
+ from backend.models.user import User # make sure this line exists
62
+ from backend.models.database import Job, Application # optional if circular import
63
  db.create_all()
64
 
65
+ # Add sample data if jobs table is empty
66
  if Job.query.count() == 0:
67
  sample_jobs = [
68
  Job(
 
88
  ),
89
  ]
90
 
91
+ for job in sample_jobs:
92
+ db.session.add(job)
93
+
94
  db.session.commit()
95
+ print("Sample jobs added to database.")
backend/models/user.py CHANGED
@@ -4,7 +4,7 @@ from backend.models.database import db # Use the shared db object
4
 
5
 
6
  class User(UserMixin, db.Model):
7
- __tablename__ = 'user'
8
  __table_args__ = {'extend_existing': True}
9
 
10
  id = db.Column(db.Integer, primary_key=True)
 
4
 
5
 
6
  class User(UserMixin, db.Model):
7
+ __tablename__ = 'users'
8
  __table_args__ = {'extend_existing': True}
9
 
10
  id = db.Column(db.Integer, primary_key=True)