Skip to content
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

ENUM error : synchroize doesn't check if enumtype already exists in postgres #5738

Closed
jeromeSH26 opened this issue Mar 22, 2020 · 11 comments
Closed

Comments

@jeromeSH26
Copy link

[ ] bug report
[ ] postgres

when synchronise is on, typeorm doesn't check if a enum type already exists when using "enumName" .

I guess a IF NO EXISTS is missing somewhere


	@Column({
		type: "enum",
		nullable: false,
		enum: ECountry,
		enumName: "ecountry",
		default: ECountry.TODEFINED,
	})
	countryBudget: ECountry;

error is the following (type already exists)

query failed: CREATE TYPE "ecountry" AS ENUM('FR', 'GR', 'TODEFINED')
error: error: le type « ecountry » existe déjà
    at Connection.parseE (C:\Users\asterix\dev\DWP_BUDGET\node_modules\pg\lib\connection.js:614:13)
    at Connection.parseMessage (C:\Users\asterix\dev\DWP_BUDGET\node_modules\pg\lib\connection.js:413:19)
    at Socket.<anonymous> (C:\Users\asterix\dev\DWP_BUDGET\node_modules\pg\lib\connection.js:129:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:273:9)
    at Socket.Readable.push (_stream_readable.js:214:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  name: 'error',
  length: 157,
  severity: 'ERREUR',
  code: '42710',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'd:\\pginstaller.auto\\postgres.windows-x64\\src\\backend\\commands\\typecmds.c',
  line: '1186',
  routine: 'DefineEnum'
}
@jeromeSH26 jeromeSH26 changed the title ENUM error : TypeOrm do not check if enumtype already exists in postgres ENUM error : synchroize doesn't check if enumtype already exists in postgres Mar 22, 2020
@imnotjames
Copy link
Contributor

Duplicate of #5748

@imnotjames imnotjames marked this as a duplicate of #5748 Oct 15, 2020
@trongrg
Copy link

trongrg commented Dec 3, 2020

@imnotjames

I still got this error in 0.2.29, and your linked dupliate issue is "Update dependency mkdirp to 1.x"

@tpiecora
Copy link

Why is this closed?

@nebkat
Copy link
Contributor

nebkat commented Dec 13, 2020

GitHub autocomplete seems to have a strange behavior where it selects a completely different issue number than the one you typed, and I presume that's what has happened here. Correct one is below.

Duplicate of #5648.

@sbrighiu
Copy link

any fix for this yet?

@Distortedlogic
Copy link

bump

@sepiette
Copy link

Also running into this issue after squashing migrations. Does anyone have solutions for a workaround?

@Distortedlogic
Copy link

Does anyone have solutions for a workaround?

I have been manually editing the migrations files after generation

@sepiette
Copy link

Does anyone have solutions for a workaround?

I have been manually editing the migrations files after generation

@Distortedlogic for things like CREATE TYPE ... what does your query look like? Any examples would be helpful! Are you just updating the queryRunner.query(...) command or doing something else??

@Distortedlogic
Copy link

@sepiette If u use the same Enum in multiple tables, when the migration is generated, it will attempt to create the Enum multiple times, once per table it is used in. Simply remove the extra lines of queryRunner that create the Enum. Yes, the lines that create the Enums will look like Create Type ...

As u can see in the screenshot, there is only one create line per Enum because I removed the duplicates after generating my migration which resolves the issue (or at least it does in my case). hope this helps
14-04-2022-10-48-57
`

@sepiette
Copy link

Thanks @Distortedlogic! I might be dealing with something a little different - I'm currently trying to squash my migrations into 1 file as we're dealing with some performance issues, however the CREATE TYPE migrations are saying things like "type "member_cancellation_status_enum" already exists even if only declared once. Totally makes sense why since the enums still exist in the DB, but I basically need a CREATE IF NOT EXISTS (which query runner keeps saying is invalid).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants