You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.8 KiB
1.8 KiB
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
-
Start the MySQL database using Docker:
cd backend docker-compose up -d -
Wait a few seconds for MySQL to start, then restart your backend server
-
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:
-
Start MySQL service:
- Windows (XAMPP/WAMP): Start from control panel
- Mac:
brew services start mysql - Linux:
sudo systemctl start mysql
-
Create the database:
mysql -u root -pThen run:
CREATE DATABASE IF NOT EXISTS verto; EXIT; -
Restart your backend server
-
Log out and log back in to your application
Verify Database Connection
Run this command from the backend directory to check your database:
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:
- Your JWT authentication token contains a user ID
- When creating an organization, the system tries to link it to that user
- But the user doesn't exist in the database (because MySQL wasn't running or the DB was reset)
- 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