New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CannotExecuteNotConnectedError when running migration on Postgres #8885
Comments
Same issue here @assapir , if you find a solution please share with us 🙏 |
I didn't found a solution @assapir but i could finally run the migrations. Isn't the best solution ever but at least we could go to sleep without this exception on mind lol 😆 import dbCreateConnection from "./dbCreateConnection"
import AppDataSource from "./AppDataSource"
export default ( async () => {
await dbCreateConnection()
await AppDataSource.runMigrations()
})() |
++ Same Issue |
Same here with YunoHost Misskey:
|
same issue with misskey migrations. |
I have the same problem. However creating new table using queryRunner runs fine public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "city" ("id" SERIAL NOT NULL, "postCode" character varying NOT NULL, "communeCode" character varying NOT NULL, "communeLabel" character varying NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_b222f51ce26f7e5ca86944a6739" PRIMARY KEY ("id"))`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "city"`);
} Only when using Enitity objects I have this issue public async up(queryRunner: QueryRunner): Promise<void> {
const manager = AppDataSource.manager;
const repository = manager.getRepository(City);
await repository.save(
allCities['default'].map((rawCity) => {
const city = new City();
city.postCode = rawCity.codePostal;
city.communeCode = rawCity.codeCommune;
city.communeLabel = rawCity.nomCommune;
city.name = rawCity.libelleAcheminement;
return city;
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const manager = AppDataSource.manager;
const repository = manager.getRepository(City);
repository.clear();
} |
Same issue |
1 similar comment
Same issue |
I had to revert back |
Same issue |
@aftabaig are you saying typeorm 0.2.*? |
Yes |
I found the problem. import dotenv into your file that contains the dataSource. i also retrieve some environment variables and for some reason when dotenv does not matter the username comes as null. My code:
Configuration file: (@src/config/index.ts)
dataSource:
if it doesn't work for you, go to your node_modules/typeorm/commands/MigrationRunCommand.js folder and console log the dataSource to verify the connection data is correct. I discovered my problem this way. |
I found today that this error may be because of another completely unrelated error. I added a |
I recommend everyone first attempt what lucasgama335 and Johann150 did and add a
|
@acSpock; Hi, How do you manage to connect using ssh tunnel? could you help me with information? I hope you can support me |
i had the same issue setting up misskey. i resolved it by upgrading from postgresql 10 to 13. |
After doing some research, I've figured out that the error message comes from the line which loads exported DataSource instance from given path. dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
) In my case, the problem was that the target database was not initialized.
@assapir
You'll be able to figure out the error message if you manually add some error printing commands to the catch scope. |
i had the same issue |
Guys, if you ever face migration issues. Latest TypeOrm version failed to emphasize the current changes on the documentation.
for example:
or
for reference: https://typeorm.io/migrations#running-and-reverting-migrations |
I had the same issue today and after some debugging like @acSpock told us I finally got an error message that helped me figuring out what seems to be the problem. Including console.log(err) didn't helped but commenting the dataSource.destroy() method out I got the espected result and an error: I then found this article that solved my problems (Seems like I just had to define a password for connecting to an mysql database...) Hope that helps some of you. |
check this, it might helps. |
I was able to fix my issue with I had custom path aliases configured in my
This explains why I could use the Typeorm CLI fine from the built JS datasource, but using the TS datasource it was unable to resolve those references. |
This error is very misleading, you would believe that something is wrong with database credentials or connection options, but in my case, it was due to additional The solution was to install
|
This gist reproduces the issue: https://gist.github.com/gillepsi-swyftx/d595a281ec08c019ea12abbfa20ea058 Most of the CLI commands currently run |
Raised #9135 to move the log entry above the call to |
After a couple of hours of investigation I also came to this conclusion: If you see the error below after writing some migrations:
and it even shows when running then you probably have problem with connection or your migration code! (EDIT: or, as it turns out, entity code, including incorrect column type). Unfortunately, typeorm (or typeorm cli, or anything related) hides all compilation errors from migrations. The best way to learn what is wrong with your migration is to run:
This will show you actual errors in the code syntax and will help you solve them. In my case, it was just a typo in a variable name, but cli always reported |
same here today, 😥 |
Updating TypeORM from |
Issue Description
When trying to run a migration on Postgres DB, the migrations fail to run with
CannotExecuteNotConnectedError: Cannot execute operation on "default" connection because connection is not yet established. at DataSource.destroy (/home/assaf/Code/private/f3tw/src/data-source/DataSource.ts:284:19) at Object.handler (/home/assaf/Code/private/f3tw/src/commands/MigrationRunCommand.ts:73:46)
Expected Behavior
All migrations should run as expected.
Actual Behavior
No migrations are running, and an error is thrown:
Steps to Reproduce
npm run typeorm migration:run
my
datasource
:From looking at the code in
src/commands/MigrationRunCommand.ts
it seems like it does callawait dataSource.initialize() so I have no idea where that problem is coming from.
My Environment
Might be related to the fact that I am using npm workspace and running inside one of the projects?It does work when using
typeorm-ts-node-commonjs
but nottypeorm-ts-node-esm
Additional Context
Relevant Database Driver(s)
aurora-mysql
aurora-postgres
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: