# Database Setup Guide ## Problem You're getting a foreign key constraint error when trying to add an organization because the MySQL database isn't running. ## Quick Fix with Docker 1. **Start the MySQL database using Docker:** ```bash cd backend docker-compose up -d ``` 2. **Wait a few seconds for MySQL to start, then restart your backend server** 3. **In your frontend, log out and log back in:** - Clear browser local storage or click logout - Log in again (or sign up if needed) - Now try creating an organization ## Alternative: Use Existing MySQL Installation If you already have MySQL installed: 1. **Start MySQL service:** - Windows (XAMPP/WAMP): Start from control panel - Mac: `brew services start mysql` - Linux: `sudo systemctl start mysql` 2. **Create the database:** ```bash mysql -u root -p ``` Then run: ```sql CREATE DATABASE IF NOT EXISTS verto; EXIT; ``` 3. **Restart your backend server** 4. **Log out and log back in to your application** ## Verify Database Connection Run this command from the backend directory to check your database: ```bash node check-db.js ``` This will show you: - If the database connection is working - How many users exist - How many organizations exist ## Why This Happened The error occurred because: 1. Your JWT authentication token contains a user ID 2. When creating an organization, the system tries to link it to that user 3. But the user doesn't exist in the database (because MySQL wasn't running or the DB was reset) 4. MySQL's foreign key constraint prevents creating an organization without a valid user ## After Fixing Once the database is running and you've logged back in: - You'll be able to create organizations - The Client Mapping feature will work properly - All data will persist correctly