check-book-fields.js 992 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function checkBookFields() {
  4. try {
  5. const book = await prisma.book.findUnique({
  6. where: { id: 1 }
  7. });
  8. console.log('📖 Book ID=1 字段检查:');
  9. console.log(` title: ${book.title}`);
  10. console.log(` bookScale: ${book.bookScale}`);
  11. console.log(` description: ${book.description}`);
  12. console.log(` targetAudience: ${book.targetAudience}`);
  13. console.log(` style: ${book.style}`);
  14. console.log(` status: ${book.status}`);
  15. console.log('');
  16. if (!book.bookScale) {
  17. console.log('⚠️ bookScale为空,需要设置默认值');
  18. await prisma.book.update({
  19. where: { id: 1 },
  20. data: {
  21. bookScale: '130000'
  22. }
  23. });
  24. console.log('✅ 已设置 bookScale = 130000');
  25. }
  26. } catch (error) {
  27. console.error('错误:', error);
  28. } finally {
  29. await prisma.$disconnect();
  30. }
  31. }
  32. checkBookFields();