From c95aa3eff700de4fb6b7df4861d47dbb826ac9fc Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Sun, 5 Apr 2026 16:17:37 -0400 Subject: [PATCH] fixed login error --- backend/src/server.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/src/server.js b/backend/src/server.js index 75de7d0..60b6243 100644 --- a/backend/src/server.js +++ b/backend/src/server.js @@ -126,7 +126,10 @@ const startServer = async () => { process.env.NODE_ENV !== 'production' || autoSync || isSqlite; if (shouldSync) { console.log('🔄 Syncing database models...'); - const alter = process.env.NODE_ENV !== 'production'; + // Never use alter on SQLite: Sequelize copies via *_backup tables with NOT NULL timestamps; + // migrated rows with null created_at/updated_at → INSERT fails → crash loop (PM2 502). + const alter = + process.env.NODE_ENV !== 'production' && sequelize.getDialect() !== 'sqlite'; await sequelize.sync({ alter }); console.log('✅ Database models synchronized'); } else { @@ -147,12 +150,15 @@ const startServer = async () => { console.log(`🔔 Notifications: http://localhost:${PORT}/api/notifications`); }); } catch (error) { - console.error('❌ Database connection failed:', error.message); - console.log('💡 Please ensure PostgreSQL is running and the database credentials are correct.'); - console.log('💡 You can also try:'); - console.log(' 1. Check if PostgreSQL service is running'); - console.log(' 2. Verify database credentials in .env file'); - console.log(' 3. Create the database: CREATE DATABASE luckychit;'); + const d = sequelize.getDialect(); + console.error('❌ Server startup failed:', error.message); + if (error.errors) console.error(error.errors.map((e) => e.message).join('; ')); + if (d === 'sqlite') { + console.log('💡 SQLite: check SQLITE_STORAGE path, file permissions, and avoid sync alter with bad data.'); + } else { + console.log('💡 Ensure the database is running and credentials in .env are correct.'); + console.log('💡 Create the DB if needed: CREATE DATABASE luckychit;'); + } process.exit(1); } };