Frequently Asked Questions
#
How can I synchronize my database schema with the entities?There are two ways:
#
I cannot run the CLIMake sure you install @mikro-orm/cli
package locally. If you want to have
global installation, you will need to install driver packages globally too.
createQueryBuilder()
method#
EntityManager does not have The method is there, the issue is in the TS type.
In v4 the core
package, where EntityManager
and EntityRepository
are
defined, is not dependent on knex, and therefore it cannot have a method
returning a QueryBuilder
. You need to import the SQL flavour of the EM
from the driver package to access the createQueryBuilder()
method.
The SQL flavour of EM is actually called
SqlEntityManager
, it is exported both under this name and underEntityManager
alias, so you can just change the location from where you import.
Same applies for the aggregate()
method in mongo driver:
The mongo flavour of EM is actually called
MongoEntityManager
, it is exported both under this name and underEntityManager
alias, so you can just change the location from where you import.
#
How can I add columns to pivot table (M:N relation)You should model your M:N relation transparently, via 1:m and m:1 properties. More about this can be found in Composite Keys section.
em.flush()
from inside lifecycle hook handlers#
You cannot call You might see this validation error even if you do not use hooks. If that happens,
the reason is usually because you do not have request context set up properly, and
you are reusing one EntityManager
instance.
string/Date/number/...
#
Column is being created with JSON type while the TS type is You are probably using the default ReflectMetadataProvider
, which does not
support inferring property type when there is a property initializer.
There are two ways around this:
- use TsMorphMetadataProvider
- specify the type explicitly: