fix: create mock user to resolve FK constraint issue
Issues fixed: 1. Frontend port is 3000 (not 5173) 2. Projects API returns 500 due to missing user 3. Foreign key constraint violation on projects_user_id_fkey Solutions: - Created create-mock-user.ts script - Added user-mock-001 to database - Created startup guide (娴嬭瘯鍜屽惎鍔?md) - Created one-click launcher (涓€閿惎鍔?bat) - Created diagnostic tool (璇婃柇闂.bat) New files: - backend/src/scripts/create-mock-user.ts - 娴嬭瘯鍜屽惎鍔?md - 涓€閿惎鍔?bat - 璇婃柇闂.bat
This commit is contained in:
43
backend/src/scripts/create-mock-user.ts
Normal file
43
backend/src/scripts/create-mock-user.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function createMockUser() {
|
||||
try {
|
||||
console.log('🔄 正在创建模拟用户...');
|
||||
|
||||
// 检查用户是否已存在
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { id: 'user-mock-001' },
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
console.log('✅ 模拟用户已存在');
|
||||
console.log('用户信息:', existingUser);
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建模拟用户
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
id: 'user-mock-001',
|
||||
email: 'demo@example.com',
|
||||
password: 'mock-password-hash', // 模拟密码(实际应用需要加密)
|
||||
name: '演示用户',
|
||||
role: 'user',
|
||||
status: 'active',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('✅ 模拟用户创建成功!');
|
||||
console.log('用户信息:', user);
|
||||
} catch (error) {
|
||||
console.error('❌ 创建模拟用户失败:', error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
createMockUser();
|
||||
|
||||
Reference in New Issue
Block a user