Replies: 17 comments 19 replies
-
Are you able to run |
Beta Was this translation helpful? Give feedback.
-
Yes, schema:create does create the database and tables. |
Beta Was this translation helpful? Give feedback.
-
Do you have a migrations table that is created as well? Does it have any data there? |
Beta Was this translation helpful? Give feedback.
-
When I run migration:up the migration table is created but empty |
Beta Was this translation helpful? Give feedback.
-
Maybe a misconfiguration? What does migration:pending say? Could be that your cli is looking for js files instead of ts? Please provide a reproduction repo so we can help you better. |
Beta Was this translation helpful? Give feedback.
-
From the output it seems to read ts files, also migrations:create is creating the migration.ts file, so I think is reading ts files correctly. migration:pending outputs: [discovery] - entity discovery finished, found 46 entities, took 2168 ms |
Beta Was this translation helpful? Give feedback.
-
If your migrations table is empty then it leads me to believe that your configuration is wrong. But as I said before, please create a reproduction so we can have a look. |
Beta Was this translation helpful? Give feedback.
-
Hello, so in the process of creating a reproduction I identified my issue is related to the .env file. after removing the config variables from my .env file it worked. So the question I have now is it possible to use the CLI with the configuration in an .env file only or it's mandatory to use a mikro-orm.config.ts file? I was hoping on not adding mikro-orm to my package.json and not creating a mikro-orm.config.ts. I tried adding thes two to my .env file but it keeps looking Error: MikroORM config file not found in ['./mikro-orm.config.js'] Thanks for your help. |
Beta Was this translation helpful? Give feedback.
-
I haven't verified, but you should be able to drive mikro-orm from only env vars. See: https://mikro-orm.io/docs/configuration/#using-environment-variables |
Beta Was this translation helpful? Give feedback.
-
Thanks @genu that's my thinking. I can run the application from .env, the problem I have is with the CLI The ones related to the CLI are missing in the example and I can't find a working example of .env and CLI. |
Beta Was this translation helpful? Give feedback.
-
🤔 From what I can tell, if the config doesn't exist, it checks for envs: mikro-orm/packages/core/src/utils/ConfigurationLoader.ts Lines 40 to 44 in f16b236 Have you made sure that |
Beta Was this translation helpful? Give feedback.
-
Hi, yes the env variables are being loaded. |
Beta Was this translation helpful? Give feedback.
-
how are you checking that they are loaded? |
Beta Was this translation helpful? Give feedback.
-
I havent read this very carefully, but:
I don't follow how you expect things to work if you don't install the ORM. You don't need to have ORM config if you provide everything needed via env vars, but not everything is configurable via env vars (e.g. you can't pass classes or instances that way and some things like subscribers can't be setup differently). Also note that you might not need/want to use initial migration. They are designed for a specific use case where you might already have the schema set up but want to start using migrations. If you do not have any schema and just have entities, drop the initial flag and just create new migration. They you need to run it (via An initial migration, if you already have the schema set up, will be automatically marked as executed, therefore added to the list you get via
Env vars are checked always. They have precedence over what is in the ORM config file. That code you highlighted is just a validation, if there are no env vars, no CLI config and no ORM config provided in the Lastly, it is always better to provide a reproduction repository if you struggle with describing something. Code is almost always more worthy than words in this context. |
Beta Was this translation helpful? Give feedback.
-
I forked the Koa example with an .env file and removed the mikro config from package.json, if you run npx mikro-orm migration:create you'll get an error. |
Beta Was this translation helpful? Give feedback.
-
I have the same problem, on windows (using the version 5.4.1-dev.13 to have this fix), and after some debugging I noticed that it could be related to Umzug, used under the hood, that does not handle glob with If I replace them just before giving it to Umzug it fixes the problem. let migrations: InputMigrations<any> = {
glob: join(this.absolutePath, this.options.glob!),
resolve: (params: MigrationParams<any>) => this.resolve(params),
}; with: let migrations: InputMigrations<any> = {
glob: join(this.absolutePath, this.options.glob!).replaceAll('\\', '/'),
resolve: (params: MigrationParams<any>) => this.resolve(params),
}; (located here) Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hi @B4nan! First of, awesome library. Been a while since I got my hands on ORMs, and it was a delight using MikroORM. So, I spent a whole day trying to figure out why the migration script is executing successfully yet my tables aren't created on a fresh deployment. While it took me a while to realize what was wrong, it was actually your comment that gave me the realization that I may have been confused between migrations and schema generation, especially from someone who came from Laravel (1 that is) where I had to write the actual migrations myself. To help others in my situation, I would like to suggest two things:
|
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Hello I've manage to create the initial migrations ts file but when I run migration:up looks like the migration up is not being run.
I just don't know what else todo. what am i missing?
Stack trace
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I'm expecting the up method to be executed.
Additional context
Versions
Beta Was this translation helpful? Give feedback.
All reactions