entityPrefix is hardcoded on migrations
Author: thegiantbeastCreated Apr 26, 2022Updated Sep 23, 2026
Labelsbug
Issue Description
My project defines an entityPrefix that is configurable through env variables.
Everything works great until I generate a migration because then the generated output query hardcodes the entityPrefix, and it's no longer flexible.
Expected Behavior
I would expect that the generated migrations would take entityPrefix into account so that it doesn't hardcode it and allows the projects to change it based on external factors, like env variables.
Example:
await queryRunner.query(`ALTER TABLE "${entityPrefix}my_table" DROP COLUMN "foo"`);Actual Behavior
await queryRunner.query(`ALTER TABLE "hardcodedPrefix_my_table" DROP COLUMN "foo"`);Steps to Reproduce
- Change model
- Run
npx typeorm migration:generate
My Environment
| Dependency | Version |
|---|---|
| Operating System | macOs |
| Node.js version | 16.13.1 |
| Typescript version | 4.6.2 |
| TypeORM version | 0.2.45 |
Additional Context
Relevant Database Driver(s)
| DB Type | Reproducible |
|---|---|
aurora-mysql |
no |
aurora-postgres |
no |
better-sqlite3 |
no |
cockroachdb |
no |
cordova |
no |
expo |
no |
mongodb |
no |
mysql |
no |
nativescript |
no |
oracle |
no |
postgres |
yes |
react-native |
no |
sap |
no |
spanner |
no |
sqlite |
no |
sqlite-abstract |
no |
sqljs |
no |
sqlserver |
no |
Are you willing to resolve this issue by submitting a Pull Request?
- ✖️ Yes, I have the time, and I know how to start.
- ✅ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
Source: typeorm/typeorm