小编Dan*_*eer的帖子

验证错误:不允许将全局实体管理器实例方法用于上下文特定操作

使用 MikroORM 并收到此错误:


ValidationError: Using global EntityManager instance methods for context specific actions is disallowed.
If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead
Run Code Online (Sandbox Code Playgroud)

其对应的代码如下:


import { MikroORM } from "@mikro-orm/core";
import { __prod__ } from "./constants";
import { Post } from "./entities/Post";
import mikroConfig from "./mikro-orm.config";

const main = async () => {
  const orm = await MikroORM.init(mikroConfig);
  const post = orm.em.create(Post, {
    title: "my first post",
  });
  await orm.em.persistAndFlush(post); …
Run Code Online (Sandbox Code Playgroud)

node.js typescript graphql mikro-orm

20
推荐指数
2
解决办法
8825
查看次数

标签 统计

graphql ×1

mikro-orm ×1

node.js ×1

typescript ×1