이슈 - error: error: relation already exists
애러 원인
-@Entity({ name: 'member-strategy' })
+@Entity({ name: 'member_strategy' })
애러가난 쿼리 로그
query: SELECT * FROM current_schema()
query: ALTER TABLE "backtest_montly_profit_rate_chart" DROP CONSTRAINT "FK_93a18e62ffa973f2cab8b35070e"
query: ALTER TABLE "invest_profit_info" DROP CONSTRAINT "FK_332199631819fa3685bd44e8881"
query: ALTER TABLE "accumulate_profit_rate_chart" DROP CONSTRAINT "FK_ccb4a2a73895470e6062087a8f6"
query: ALTER TABLE "backtest_win_ratio" DROP CONSTRAINT "FK_884b57650427ad162308e4c4a74"
query: ALTER TABLE "operation_member_list" DROP CONSTRAINT "FK_cf4f0ea38bdeed02594d845d352"
query: ALTER TABLE "lookup_member_list" DROP CONSTRAINT "FK_aa463164cd4a94df5fe920f73ba"
query: ALTER TABLE "history" DROP CONSTRAINT "FK_36a91be799b8cd3566a3fb582f8"
query: ALTER TABLE "hash_list" DROP CONSTRAINT "FK_ab89d025dd8181a06529e06bc5c"
query: ALTER TABLE "backtest_queue" DROP CONSTRAINT "FK_2e6ed104307fb210a17d8bed9ca"
query: CREATE SEQUENCE "member_strategy_strategy_code_seq" OWNED BY "member_strategy"."strategy_code"
query failed: CREATE SEQUENCE "member_strategy_strategy_code_seq" OWNED BY "member_strategy"."strategy_code"
error: error: relation "member_strategy_strategy_code_seq" already exists
at Parser.parseErrorMessage (C:\Users\Dos\Desktop\algoridang\nestjs_server\node_modules\pg-protocol\dist\parser.js:287:98)
at Parser.handlePacket (C:\Users\Dos\Desktop\algoridang\nestjs_server\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\Users\Dos\Desktop\algoridang\nestjs_server\node_modules\pg-protocol\dist\parser.js:39:38)
at Socket.<anonymous> (C:\Users\Dos\Desktop\algoridang\nestjs_server\node_modules\pg-protocol\dist\index.js:11:42)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:467:12)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at Socket.Readable.push (internal/streams/readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
length: 127,
severity: 'ERROR',
code: '42P07',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'heap.c',
line: '1164',
애러 메시지 분석
- member_strategy_strategy_code_seq 가 이미 있다?
- 어? 나는 member_strategy_strategy_code_seq을 만든적이 없다!
- 가만 보니, 테이블이 아니고 SEQUENCE 라는 객체이고 찾아보니
- AutoIncrement기능을 사용할때 카운트값을 기록해 두는 시퀀서 였다.
query failed: CREATE SEQUENCE "member_strategy_strategy_code_seq" OWNED BY "member_strategy"."strategy_code"
error: error: relation "member_strategy_strategy_code_seq" already exists
해결방법
- pgAdmin 에서 직접 시퀀스를 살펴보니 member-strategy 현재 카운트는 12까지 측정되었다.
- 시퀀서는 이름 바꾸기 전과 후 모두 삭제를 했다.
- member_strategy_strategy_code_seq 삭제
- member-strategy_strategy_code_seq 삭제
- TypeORM을 다시 키고, 동기화를 진행한다.
- 1로 초기화된 시퀀스가 만들어지고 12로 셋팅한다.
끝